OpenCascade学习笔记之GeomAPI_ExtremaCurveCurve

今天在研究三维空间直线和圆相交的问题上,遇到了一个小小的问题。但是方法总比困难多,通过自己的不懈努力,终于解决了这个问题。
在开始学习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);
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值