Locate an AIS_Trihedron at the origin that given with gp_Pnt

Dear OCCT Community,

I have added a sphere to a vertex I have chosen in the scene and I am trying to locate an AIS_Trihedron at the origin of this sphere. The direction information is correct, but its position is far from where I set it and it is drawn. I've added the image about this issue and I am sharing my method below:

void VisualizerWidget::createTrihedronWithOriginPoint(TopoDS_Shape ais_shape, gp_Pnt origin_xyz)
    gp_Ax2 Position;

    Handle_Geom_Axis2Placement axis = new Geom_Axis2Placement(Position);
    Handle_AIS_Trihedron aisTrihedron = new AIS_Trihedron(axis);

    aisTrihedron->SetDatumPartColor(Prs3d_DP_XAxis, Quantity_NOC_RED2);
    aisTrihedron->SetDatumPartColor(Prs3d_DP_YAxis, Quantity_NOC_GREEN2);
    aisTrihedron->SetDatumPartColor(Prs3d_DP_ZAxis, Quantity_NOC_BLUE2);
    aisTrihedron->SetLabel(Prs3d_DP_XAxis, "X");
    aisTrihedron->SetLabel(Prs3d_DP_YAxis, "Y");
    aisTrihedron->SetLabel(Prs3d_DP_ZAxis, "Z");
                new Graphic3d_TransformPers(Graphic3d_TMF_ZoomPers, axis->Ax2().Location()));

    ais_interactive_context_->Display(aisTrihedron, true);

I haven't figured out where I went wrong yet. If you have any suggestions for a solution about this issue, I'm looking forward to hearing. Thank you in advance!

Kirill Gavrilov's picture

                new Graphic3d_TransformPers(Graphic3d_TMF_ZoomPers, axis->Ax2().Location()));

Check the documentation of Graphic3d_TransformPers. It requires an extra caution when it comes to location. So that if you want to use Graphic3d_TMF_ZoomPers, you need defining object's origin as identity and pass this point to Graphic3d_TransformPers.

Nezihe Sözen's picture

Thank you very much for your reply to my question. Thanks to your blog, I am now able to change the location of the AIS_Trihedron. However, I couldn't change its rotation, I'm probably missing a point again.

Normally, if I would like to change a TopoDS_Shape, I use below implementation (and it works correctly):

TopoDS_Shape OCCTWidget::setRotation(int a, int b, int c, TopoDS_Shape shape)
    gp_Trsf trsf;

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

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

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

    return shape;


But if I would like to rotate the AIS_Trihedron, I am not able to rotate it. How can I change the rotation of AIS_Trihedron? Or how can I convert/transform the AIS_Trihedron to TopoDS_Shape? Like below implementations, is it possible convert AIS_Trihedron to TopoDS_Shape?

Example 1: TopoDS_Shape topods_sphere_shape = BRepPrimAPI_MakeSphere(origin_xyz, sphere_radius).Shape();

Example 2:TopoDS_Shape topods_box_shape= BRepPrimAPI_MakeBox(10, 20, 30).Shape();

Best regards and thank you!

Nezihe Sözen's picture

Hello again, Please ignore the previous message I wrote, because there are many logic errors there. If I had set setDirection like I set setLocation I could see the rotation of AIS_Trihedron changed and now I've managed to do this.

gp_Ax2 Position; 
Position.SetDirection(gp_Dir(rotation_Ox,rotation_Oy, rotation_Oz));

My aim was to change the main AIS_Trihedron of the Scene only with mouse movements or with AIS_ViewCube; while the AIS_Trihedron above the selected vertex I was able to move independently of the main AIS_Trihedron of the scene. Anyway, my problem and question have been solved.

Thank you again for all your support...