Opencascad 判断点在图形内外

Posted JeasonLiu先生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Opencascad 判断点在图形内外相关的知识,希望对你有一定的参考价值。

程序摘自OccTry中:

二维情况:

在kcgBRepLib.cpp中

 1 BRepTopAdaptor_FClass2d fcls(aNF,Precision::PConfusion());
 2 
 3     TopExp_Explorer ex;
 4     for(ex.Init(aW2,TopAbs_VERTEX);ex.More();ex.Next())
 5     {
 6         TopoDS_Vertex aV = TopoDS::Vertex(ex.Current());
 7         gp_Pnt pnt = BRep_Tool::Pnt(aV);
 8 
 9         GeomAPI_ProjectPointOnSurf pp(pnt,fpln.Plane());
10         if(pp.IsDone() && pp.NbPoints() > 0)
11         {
12             gp_Pnt2d uv;
13             double u,v;
14             pp.LowerDistanceParameters(u,v);
15             uv.SetCoord(u,v);
16             //验证是否在aW1内部
17             TopAbs_State sta = fcls.Perform(uv);///该状态量只能用在二维中。。。
18             if(sta == TopAbs_IN)
19             {
20                 bIN = TRUE;
21                 break;
22             }
23         }
24         else
25         {
26             nC ++;
27             if(nC > 3)
28                 break;
29         }
30     }

三维情况:

kcmShapeAnalysis.cpp中

 1 BOOL    kcmShapeAnalysisFaceOrient::CalcNormal()
 2 {
 3     ClearArrowDisp();
 4 
 5     //
 6     TopoDS_Face aFace;
 7     TopExp_Explorer ex;
 8     kcDispFrameArrow *pArrow = NULL;
 9     kPoint3 p;
10     kVector3 norm;
11     int ix,nbShape = m_pInputFace->NbSelectedShape();
12     for(ix = 0;ix < nbShape;ix ++)
13     {
14         aFace = TopoDS::Face(m_pInputFace->SelectedShape(ix));
15         //
16         if(kcgSurfLib::CalcFaceNormal(aFace,m_bTopoNormal,p,norm))
17         {
18             pArrow = new kcDispFrameArrow(m_pModel->GetAISContext());
19             pArrow->SetColor(kColor(0.0,1.0,1.0));
20             pArrow->SetPixelLen(50,20,15);
21             pArrow->Set(p,norm);
22             pArrow->Display(TRUE);
23 
24             m_arrowList.push_back(pArrow);
25         }
26         // calc wire
27         TopoDS_Iterator ite;
28         for(ite.Initialize(aFace);ite.More();ite.Next())
29         {
30             TopoDS_Wire aWire = TopoDS::Wire(ite.Value());
31             TopoDS_Iterator wite;
32             for(wite.Initialize(aWire);wite.More();wite.Next())
33             {
34                 TopoDS_Edge aE = TopoDS::Edge(wite.Value());
35                 //
36                 if(kcgCurvLib::CalcTangent(aE,aFace,m_bTopoNormal,p,norm))
37                 {
38                     pArrow = new kcDispFrameArrow(m_pModel->GetAISContext());
39                     pArrow->SetColor(kColor(1.0,0.0,1.0));
40                     pArrow->SetPixelLen(50,20,15);
41                     pArrow->Set(p,norm);
42                     pArrow->Display(TRUE);
43 
44                     m_arrowList.push_back(pArrow);
45                 }
46             }
47         }
48     }
49 
50     return TRUE;
51 }

 

以上是关于Opencascad 判断点在图形内外的主要内容,如果未能解决你的问题,请参考以下文章

平面中判断点在三角形内算法(重心法)

怎么判断某一点在一个不规则的图形内部

空间中判断点在三角形内算法(方程法)

图形学笔记八 Geometry 几何

如何判断一个点在多边形内

nx二次开发怎么判断线上某一点在面上