Hi,
I don't understand how to make multiple transformations or how to rotate around a pivot to get a valid result. I'm not sure if it is a problem with the order in which it should happen or am I misunderstanding things how it is meant to work. The gp_Trsf seems to make one transformation at a time and therefor multiple gp_Trsf must be chained to get the result.
As per documentation of opencascade (https://dev.opencascade.org/doc/overview/html/occt_user_guides__modeling_data.html#occt_modat_5_1) I need to create a gp_Trsf for every transformation and chain them using TopLoc_Location.Multiplied().
This is what I do so far:
This is the process in screenshots, the red arrow points to the pivot and the yellow to 0,0,0:
it works and looks like this when turning 90 degree on the pivot (25, 758, 33) and looks like this:
When doing the same with the opposite bracket assembly is won't work:
It already has a rotate information which I'm multiplying with when doing the rotate but the offset is not working. I tried quite a few different ways but it does not end in the location where it should be. I also suspect that I didn't understand how the rotation works?
I already had that question on occ forum but digged a little deeper since. If I've got an answer I will reply to both.
Any help or hint is appreciated...
Thanks!
I don't understand how to make multiple transformations or how to rotate around a pivot to get a valid result. I'm not sure if it is a problem with the order in which it should happen or am I misunderstanding things how it is meant to work. The gp_Trsf seems to make one transformation at a time and therefor multiple gp_Trsf must be chained to get the result.
As per documentation of opencascade (https://dev.opencascade.org/doc/overview/html/occt_user_guides__modeling_data.html#occt_modat_5_1) I need to create a gp_Trsf for every transformation and chain them using TopLoc_Location.Multiplied().
This is what I do so far:
C++:
TopLoc_Location rotate(TopLoc_Location& world, double angle, int axis, gp_XYZ rotationPosition) {
gp_Quaternion RX(gp::DX(), 0.);
gp_Quaternion RY(gp::DY(), 0.);
gp_Quaternion RZ(gp::DZ(), 0.);
switch (axis) {
case 1: RX.Set(gp_Quaternion(gp::DX(), angle / 180 * M_PI)); break;
case 2: RY.Set(gp_Quaternion(gp::DY(), angle / 180 * M_PI)); break;
case 3: RZ.Set(gp_Quaternion(gp::DZ(), angle / 180 * M_PI)); break;
}
gp_Quaternion RA(RZ * RY * RX);
gp_Trsf compoundTransform = gp_Trsf(world);
TopLoc_Location result;
gp_XYZ compoundPosition = gp_XYZ(compoundTransform.TranslationPart());
gp_XYZ distanceToPivot = compoundPosition.Subtracted(rotationPosition);
// 0
TopLoc_Location compoundPositionLocation = TopLoc_Location(world);
// 1
// Bring object which should be rotated to actual rotate position
gp_Trsf rotationPositionTrsf;
rotationPositionTrsf.SetTranslation(rotationPosition);
TopLoc_Location rotationPositionLocation(rotationPositionTrsf);
// 2
// The rotation itsself
gp_Trsf rotationTrsf;
RA.Multiply(compoundTransform.GetRotation());
rotationTrsf.SetRotation(RA);
TopLoc_Location rotationLocation(rotationTrsf);
// 3
// Objekt auf die Differenz schieben vom eigentlichen Drehpunkt damit wieder auf Originalposition
gp_Trsf rotationCompoundDifferenceTrsf;
rotationCompoundDifferenceTrsf.SetTranslation(distanceToPivot);
TopLoc_Location rotationCompoundDifferenceLocation(rotationCompoundDifferenceTrsf);
result = compoundPositionLocation * rotationPositionLocation * rotationLocation * rotationCompoundDifferenceLocation;
return result;
}
This is the process in screenshots, the red arrow points to the pivot and the yellow to 0,0,0:
it works and looks like this when turning 90 degree on the pivot (25, 758, 33) and looks like this:
When doing the same with the opposite bracket assembly is won't work:
It already has a rotate information which I'm multiplying with when doing the rotate but the offset is not working. I tried quite a few different ways but it does not end in the location where it should be. I also suspect that I didn't understand how the rotation works?
I already had that question on occ forum but digged a little deeper since. If I've got an answer I will reply to both.
Any help or hint is appreciated...
Thanks!