OpenCascade学习笔记之GeomAPI_ExtremaCurveCurve

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014801811/article/details/84591760

今天在研究三维空间直线和圆相交的问题上,遇到了一个小小的问题。但是方法总比困难多,通过自己的不懈努力,终于解决了这个问题。
在开始学习OCC时,我们可能在MFCSample中见到一个曲线求交的例子。具体代码如下:

Handle(TColgp_HArray1OfPnt2d) harray =                              
    new TColgp_HArray1OfPnt2d (1,5); // sizing harray               
harray->SetValue(1,gp_Pnt2d (0,0));                                 
harray->SetValue(2,gp_Pnt2d (-3,1));                                
harray->SetValue(3,gp_Pnt2d (-2,5));                                
harray->SetValue(4,gp_Pnt2d (2,9));                                 
harray->SetValue(5,gp_Pnt2d (-4,14));                               
                                                                    
Geom2dAPI_Interpolate anInterpolation(harray,Standard_False,0.01);  
anInterpolation.Perform();                                          
Handle(Geom2d_BSplineCurve) SPL = anInterpolation.Curve();          
                                                                    
gp_Pnt2d P1(-1,-2);                                                 
gp_Pnt2d P2(0,15);                                                  
gp_Dir2d V1 = gp::DY2d();                                           
Handle(Geom2d_TrimmedCurve) TC1=                                    
    GCE2d_MakeSegment(P1,V1,P2);                                    
                                                                    
Standard_Real tolerance = Precision::Confusion();                   
Geom2dAPI_InterCurveCurve ICC (SPL,TC1,tolerance);                  
Standard_Integer NbPoints =ICC.NbPoints();                          
gp_Pnt2d PK;                                                        
for (Standard_Integer k = 1;k<=NbPoints;k++)                        
  {                                                                 
    PK = ICC.Point(k);                                              
    // do something with each intersection point                    
  }                                                                 

但是此方法只适合2维平面内的曲线求交。使用的方法: Geom2dAPI_InterCurveCurve,显然这种方法无法适用于3D曲线。这里介绍一种解决3D曲线求交运算的方法。
OCC官方文档是这样描述的:

Describes functions for computing all the extrema between two 3D curves. An ExtremaCurveCurve algorithm minimizes or maximizes the distance between a point on the first curve and a point on the second curve. Thus, it computes start and end points of perpendiculars common to the two curves (an intersection point is not an extremum unless the two curves are tangential at this point). Solutions consist of pairs of points, and an extremum is considered to be a segment joining the two points of a solution. An ExtremaCurveCurve object provides a framework for:

  • defining the construction of the extrema,
  • implementing the construction algorithm, and
  • consulting the results. Warning In some cases, the nearest points between two curves do not correspond to one of the computed extrema. Instead, they may be given by:
  • a limit point of one curve and one of the following: its orthogonal projection on the other curve,
  • a limit point of the other curve; or
  • an intersection point between the two curves.

使用方法:


GeomAPI_ExtremaCurveCurve::GeomAPI_ExtremaCurveCurve	(	const Handle< Geom_Curve > & 	C1,
                                                         const Handle< Geom_Curve > &    C2 )

GeomAPI_ExtremaCurveCurve aExtCurve;
aExtCurve.Init(aCurve,prsentCurve);
Standard_Integer NbResults = aExtCurve.NbExtrema();
gp_Pnt p1,p2,p3,p4
aExtCurve.Points(1,p1,p2);
aExtCurve.Points(2,p3,p4);

猜你喜欢

转载自blog.csdn.net/u014801811/article/details/84591760