Rotation lost when mirror is applied

We've got a problem with transformation getting mangled somehow when trying to mirror objects. We are reading data from a STEP model file, and applying the relevant rotate/mirror/shift elements of transformation to apply the shapes in the model to the components on our design. It all works fine for unmirrored items, but when we apply mirroring to the gp_Trsf transform it seems to wipe out the rotation. If we re-order the r/m/s to be s/m/r, we get the correct rotation but wrong shift and only one item is mirrored.

Our code is roughly like this:

Handle(TopTools_HSequenceOfShape) ShapeSequence;
//....read stuff from STEP file, then.....
CPoint SymPos = SymbolCentre;
gp_Pnt Position(Convert(SymPos.x),Convert(SymPos.y),Convert(Depth));
gp_Trsf trsf;
if (Angle!=0)
{
gp_Ax1 RAxis(gp_Pnt(0,0,0),gp_Dir(0,0,1.0));
trsf.SetRotation(Axis,Angle*PI/180.0);
}
if (Mirrored)
{
gp_Ax1 MAxis(gp_Pnt(0,0,0),gp_Dir(0,1.0,0));
trsf.SetMirror(MAxis);
}
trsf.SetTranslationPart(gp_Vec(Position.XYZ()));
TopLoc_Location location(trsf);
TopoDS_Shape Shape=ShapeSequence->Value(i);
Shape.Location(location);
//....now draw the shape....

As our unmirrored items work, it seems that SetTranslationPart isn't interfering with the Angle we've applied, but Mirror certainly does seem to reset the Angle.

We're continuing to delve in the sample code etc to work out what we're doing wrong, but any clues would be gratefully received!

David

Sharjith Naramparambath's picture

Hi David,

To make a complex transformation, you need to use the method Multiply. Simply using the Set method will apply only that transformation (by resetting the older transformation). See the reference documentation for the gp_Trsf class. In your case you need to first create trsf1 and trsf2 and then trsf1.SetRotation(...) and trsf2.SetMirror(...) and then trsf1.Multiply(trsf2) to get the combined transformation.

Sharjith