Computing distance between gp_Pnt and gp_Ax1 in OpenCASCADE
OCCUtils provides convenience functions for computing the orthogonal direction to two directions:
#include <occutils/Axis.hxx>
using namespace OCCUtils;
gp_Ax1 axis = /* ... */;
gp_Pnt pnt = /* ... */;
double distance = Axis::Distance(axis, pnt);
Alternatively, you can also use Point::Distance()
which internally just calls Axis::Distance()
but might make your code more readable under some circumstances. Note that the argument order is inverted!
#include <occutils/Point.hxx>
using namespace OCCUtils;
gp_Ax1 axis = /* ... */;
gp_Pnt pnt = /* ... */;
double distance = Point::Distance(pnt, axis);
In case you can’t useĀ *OCCUtils,*here’s the code to do it manually:
double distance = gp_Lin(axis).Distance(pnt);