How to converts the position of a point in global coordinate system to position in a local coordinate system


CAD community veteran
Hi Bros, I got an axis (gp_Ax1), it's the axis of symmetry from a cylinder; and I also have a point.

I want to get the shortest distance from point to axis.

I have two ideas:
(1) create a line (gp_Lin) with the axis (gp_Ax1), and then find a tool to get the shortest distance.
However, I didn't find a tool to calculate the the shortest distance between line and point. (I find the
tool:GeomAPI_ProjectPointOnCurve, it can get the extrema between point and curve).

(2) get the local coordinate system from the cylinder, and converts the position of the point in global coordinate system to position in the local coordinate system, then can get the shortest distance easy.
However, I don't know how to complete it.

So I try to get help from you.


Staff member
Use the Distance() method of gp_Lin:

//! Computes the distance between <me> and the point theP.
Standard_Real Distance (const gp_Pnt& theP) const;