在 OpenCASCADE 中计算 gp_Pnt 和 gp_Ax1 之间的距离

OCCUtils 提供了计算两个方向的正交方向的便捷函数:

axis_distance.cpp
#include <occutils/Axis.hxx>
using namespace OCCUtils;

gp_Ax1 axis = /* ... */;
gp_Pnt pnt = /* ... */;
double distance = Axis::Distance(axis, pnt);

或者,你也可以使用 Point::Distance(),它内部只是调用 Axis::Distance(),但在某些情况下可能使你的代码更易读。注意参数顺序是反转的!

point_distance.cpp
#include <occutils/Point.hxx>
using namespace OCCUtils;

gp_Ax1 axis = /* ... */;
gp_Pnt pnt = /* ... */;
double distance = Point::Distance(pnt, axis);

如果你不能使用 OCCUtils,这里是手动执行的代码:

manual_distance.cpp
double distance = gp_Lin(axis).Distance(pnt);

Check out similar posts by category: C/C++, OpenCASCADE