# Not sure how to do rotation in gp_Trsf SetTransformation()

Hello --

I'm looking to rotate an object around its center and translate it to a particular location. It seems that the best way to handle this is using gp_Trsf's SetTransformation().

While I have no problem translating the object to a particular location, correctly rotating the object has proven to be a bit tricky. Specifically, I am rotating the object at 45 degree angles, but beyond a certain point (I think around 90 degrees) each subsequent 45 degree turn gets smaller and smaller. I suspect there is something wrong with the assumptions I'm making as far as what to feed in for the rotation.

The relevant input parameters in this example are rotX, rotY, and rotZ, which are the degrees to rotate the object along its respective X, Y, and Z axis. Any idea on what I'm doing wrong?

------------------------------------

gp_Trsf trsf;
trsf.SetTransformation(gp_Quaternion(rotX * (M_PI/180),
rotY * (M_PI/180),
rotZ * (M_PI/180),
(Standard_Real)1),
gp_Vec(locX, locY, locZ));

shape.Location(TopLoc_Location(trsf));

------------------------------------

Thank you!

I should point out that I'm not repeatedly feeding in 45 degrees for the appropriate axis to make the object turn 45 degrees. I'm keeping the value stored outside of this function and feeding in the combined result. (So I might feed in 0, then feed in 45, then feed in 90, etc.)

I can make this work for one axis at a time (and no translation) with trsf.SetRotation(gp::OX(), currentRotX * (M_PI/180)) and the rotation appears to be accurate as I feed in new numbers. However, I want this sort of result in the SetTransformation along all three axes (as well as being able to translate the object).

Never mind -- I figured it out. I ended up using the delta rather than the full current value of the rotation/translation and using BRepBuilderAPI_Transform to make the rotation and translations happen:

Handle_AIS_Shape anIS = Handle_AIS_Shape::DownCast(myAISContext()->Current());
TopoDS_Shape shape = anIS->Shape();

gp_Trsf trsf;

trsf.SetRotation(gp::OX(), deltaRotX * (M_PI/180));
BRepBuilderAPI_Transform xform1(shape, trsf);
shape = xform1.Shape();

trsf.SetRotation(gp::OY(), deltaRotY * (M_PI/180));
BRepBuilderAPI_Transform xform2(shape, trsf);
shape = xform2.Shape();

trsf.SetRotation(gp::OZ(), deltaRotZ * (M_PI/180));
BRepBuilderAPI_Transform xform3(shape, trsf);
shape = xform3.Shape();

trsf.SetTranslation(gp_Vec((Standard_Real)deltaLocX, (Standard_Real)deltaLocY, (Standard_Real)deltaLocZ));
BRepBuilderAPI_Transform xform4(shape, trsf);
shape = xform4.Shape();

anIS->Set(shape);