下面是OCC库中的sample mfc工程中点投影到曲线类GeomAPI_ProjectPointOnCurve用法。
N是三维点P投影到曲线C的最近点,投影点个数为NbResults,Point(…)返回投影点
可以把Geom_Circle换成Geom_XXX.hxx中的其它种类的参数曲线试试,OCC中有直线,二次曲线,样条曲线,分2d曲线和空间3d曲线。
...
gp_Pnt N,Q,P(1,2,3);
Standard_Real distance, radius = 5;
Handle(Geom_Curve) C = new Geom_Circle(gp::XOY(),radius);
GeomAPI_ProjectPointOnCurve PPC (P,C);
N = PPC.NearestPoint();
Standard_Integer NbResults = PPC.NbPoints();
if(NbResults>0)
{
for(Standard_Integer i = 1;i<=NbResults;i++)
{
Q = PPC.Point(i);
distance = PPC.Distance(i);
// do something with Q or distance here
...
}
}
GeomAPI_XXX有下面一些类
class GeomAPI_ProjectPointOnCurve;
class GeomAPI_ProjectPointOnSurf;
class GeomAPI_ExtremaCurveCurve;
class GeomAPI_ExtremaCurveSurface;
class GeomAPI_ExtremaSurfaceSurface;
class GeomAPI_PointsToBSpline;
class GeomAPI_PointsToBSplineSurface;
class GeomAPI_Interpolate;
class GeomAPI_IntSS;
class GeomAPI_IntCS;
实现了点投影到曲线曲面(Project),曲线曲面相互之间的极值(extrema),点到样条曲线样条曲面,面面求相交曲线(intss),线面求相交点或者交线(intcs),多个点插值为样条线 这些几何算法。