how rotate the object

good afternoon

who can tell me how to rotate the object , like surface , solid .

please give me a sample .

thank .

Rob Bachrach's picture

A rotation, like any transformation, can be performed by
creating a transformation matrix and then applyling it to a
TopoDS_Shape (vertex, edge, wire, face, shell, solid).

So, to perform a rotation(r) about the global +Y axis:

gp_Trsf myTrsf;
myTrsf.SetRotation(gp::OY, r);
BRepBuilderAPI_Transform xform(myShape, myTrsf);
myShape = xform.Shape();

Note: you can also look at gce_MakeRotation if you do not wish
to create an intermediate gp_Trsf object. BRepBuilderAPI_Transform
modifies the transformation matrix on the shape.
If you use BRepBuilderAPI_GTransform it will modify the actual points,
curves, and surfaces in the shape.

wuxg's picture

thanks very much .

but i have a error like this :

error C2664: 'SetRotation' : cannot change
const class gp_Ax1' to
"const class gp_Ax1 &(__cdecl *)(void)"

Rob Bachrach's picture

Based on the error, it looks like you are trying to pass a function
pointer rather than a gp_Ax1 object into the call to SetRotation.
It is possible I had a typo in the example I sent you (it was
untested). You might try putting parentheses in the axis creation:
SetRotation(gp::OY(), r);

Sorry if this caused confusion.

Rob

wuxg's picture

thanks you very much .

I can do it . the code like this :

lsWall= BRepPrimAPI_MakeBox(3170,1400,100);
const Standard_Real r=45 ;
myTrsf.SetRotation(gp::OY(), r * PI /180 );
// or : myTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,1,0)),10);
BRepBuilderAPI_Transform xform1(lsWall, myTrsf);
lsWall = xform1.Shape();

but the ratoted angle is not my expectation .
r=45 , picture in sceen like to 60 rotate;
r=90 , picture in screen like 130 .

and if I want use BRepPrimAPI_MakeBox(A,dx,dy,dz).
to make a rotated box around gp::OY(),
what to define A .

thanks.

Rob Bachrach's picture

When calling MakeBox, A is the local coordinate system for the
box. This local coordinate system will define one corner of the
box with the box defined in the +x,+y,+z octant.
So, if you want to center your box around the global origin, the
easiest way would be to use the MakeBox call that takes a point for
a corner of the box and call (again, not tested):

BRepPrimAPI_MakeBox(gp_Pnt(-dx/2, -dy/2, -dz/2),dx,dy,dz);

Likewise, if you really wanted to use the local coordinate system
method, you just need to set its origin:

gp_Ax2 myAx2;
myAx2.SetLocation(gp_Pnt(-dx/2, -dy/2, -dz/2));
BRepPrimAPI_MakeBox(myAx2, dx, dy, dz);

This coordinate system is aligned with the global cartesian
coordinate system. Likewise, although not necessary in this case,
you can specify its orientation by specifying either its main axis
(equivalent to +Z) and letting it compute the others or by specifying
the X and Z axes and letting it compute y.

gp_Ax2 myAx2(gp_Pnt(-dx/2, -dy/2, -dz/2), gp::DZ(), gp::DX());
BRepPrimAPI_MakeBox(myAx2, dx, dy, dz);

wuxg's picture

sorry .

the first question is my misstake.

the rotate angle r=angle ;

myTrsf.SetRotation(gp::OY(), r * PI /180 );

I can see right result .

sorry.