hi @blobfish, good link)
I guess you are talking about working directly with the data structures combined with the implicit sharing(COW) nature of OpenCasCade? The modeling algorithms do, or at least should, handle COW. I mean the following works as expected. Did I not understand your point?Be careful here, this case is appropriate for us only if we are ready to change basic TopoDS_Shape. If in our application we may not changing it, but would like working with the topology changed , it's also possible to create a copy of the shape and set location for this copy (the method is EmptyCopied of the shape - see internal implementation of AIS_ColoredShape or draw command as example of using it)
TopoDS_Solid box0 = BRepPrimAPI_MakeBox(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(10.0, 10.0, 10.0)).Solid();
gp_Trsf freshTransform;
freshTransform.SetTranslation(gp_Vec(5.0, 5.0, 5.0));
TopLoc_Location freshLocal(freshTransform);
auto box1 = box0.Located(freshLocal);
BRepAlgoAPI_Fuse bop0(box0, box1);
auto out0 = bop0.Shape();
assert(!out0.IsNull());
ocs::writeBRep(out0, "locatedBool0.brep");
BRepAlgoAPI_Fuse bop1(box0, box1);
auto out1 = bop1.Shape();
assert(!out1.IsNull());
ocs::writeBRep(out1, "locatedBool1.brep");
ocs::dumpShapes(out1);
ocs::dumpCheck(out1);
Rotations are understood to be at absolute origin. So what you can do is create a translation matrix from your desired rotation point to absolute, apply the rotation and then translate back. sudo code:The part I created is translating and rotating nicely, but do you know how could I rotate it according to its center point and not to the global one?
template <Matrix> Matrix rotationAboutPoint(const Matrix &rotation, const Matrix::vector_type &rotationPoint)
{
Matrix translation = Matrix::createTranslation(rotationPoint);
return -translation * rotation * translation;
}
gp_Pnt pto2t(translation.x(),translation.y(),translation.z());
rotxTrsf.SetRotation(gp_Ax1(pto2t,gp_Dir(1,0,0)),DEGREE2RAD( rotation.x()));
rotyTrsf.SetRotation(gp_Ax1(pto2t,gp_Dir(0,1,0)),DEGREE2RAD( rotation.y()));
rotzTrsf.SetRotation(gp_Ax1(pto2t,gp_Dir(0,0,1)),DEGREE2RAD( rotation.z()));
gp_Trsf transformacion = rotxTrsf*rotyTrsf*rotzTrsf;
Sorry for bumping this 1 year old topic, I don't wanna make a new topic for such a small question.I solved it in this way, in SetRotation can be defined the rotation point, which is previously translated.
C++:gp_Pnt pto2t(translation.x(),translation.y(),translation.z()); rotxTrsf.SetRotation(gp_Ax1(pto2t,gp_Dir(1,0,0)),DEGREE2RAD( rotation.x())); rotyTrsf.SetRotation(gp_Ax1(pto2t,gp_Dir(0,1,0)),DEGREE2RAD( rotation.y())); rotzTrsf.SetRotation(gp_Ax1(pto2t,gp_Dir(0,0,1)),DEGREE2RAD( rotation.z())); gp_Trsf transformacion = rotxTrsf*rotyTrsf*rotzTrsf;
// Define your rotation angles and center point
double rx = 45.0; // Angle of rotation around the X-axis in degrees
double ry = 30.0; // Angle of rotation around the Y-axis in degrees
double rz = 60.0; // Angle of rotation around the Z-axis in degrees
gp_Pnt centerPoint(0.0, 0.0, 0.0); // Center point for rotation
// Create transformation matrices for rotation
gp_Trsf trsfRx, trsfRy, trsfRz;
trsfRx.SetRotation(gp_Ax1(centerPoint, gp_Dir(1, 0, 0)), DegreeToRad(rx));
trsfRy.SetRotation(gp_Ax1(centerPoint, gp_Dir(0, 1, 0)), DegreeToRad(ry));
trsfRz.SetRotation(gp_Ax1(centerPoint, gp_Dir(0, 0, 1)), DegreeToRad(rz));
// Combine the rotation transformations
gp_Trsf rotationTransformation = trsfRx * trsfRy * trsfRz;
// Define the translation vector
gp_Vec translationVector(10.0, 20.0, 30.0); // Adjust the values as needed
// Create a translation transformation
gp_Trsf translationTransformation;
translationTransformation.SetTranslation(translationVector);
// Combine the rotation and translation transformations
gp_Trsf finalTransformation = translationTransformation * rotationTransformation;
// Apply the final transformation to your shape