Rotate and Translate a gp_Trsf

I see that I can both translate and rotate a gp_Trsf.
Why doesn't this code work:
------------------------------------
gp_Vec veclocation(1000, 0, 0);
gp_Trsf trsf;
trsf.SetTranslation(veclocation);
trsf.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 1.57);
TopLoc_Location toploc_location(trsf);
shape.Location(toploc_location);
------------------------------------

When I both run trsf.SetTranslation(...) and trsf.SetRotation(...) only the rotation is made. When I uncomment the trsf.SetRotation(...) line the translation works...

How come I can't do both at the same time?

Rob Bachrach's picture

That's just not the way the class is defined. If you read the documentation on gp_Trsf, it says that these functions "change this transformation into..." If you want to set both, try calling SetRotation followed by a call to SetTranslationPart.

d00_ape's picture

Ok. buy now I think I trixed it up like this:
------------------------------------------------
gp_Vec veclocation(locationX, locationY, locationZ);
gp_Trsf trsf;
trsf.SetRotation(gp_Ax1(gp_Pnt(locationX, locationY, locationZ), gp_Dir(0, 0, 1)), angle);
gp_Trsf t;
t.SetTranslation(veclocation);
trsf *=t;
TopLoc_Location toploc_location(trsf);
shape.Location(toploc_location);
------------------------------------------------

"If you read the documentation... ... change this transformation into..."
-> I start to think I don't have the complete documentation (I have 5.2) Where did you read that?

TEISSANDIER's picture

You should read comments in the cdl files.

Very often, the comments in cdl files are better than the official documentation.

For example, I never read the documentation about the "gp" package.
The comments in the "gp_Trsf.cdl" file are very easy to understand and will help you to use this class.
Regards,

Denis