1 TopoDS_Edge edge0 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, 0), gp_Pnt(10, 10, 10)); 2 Geometry::instance()->addShape(ShapeType::Curve, edge0); 3 4 gp_Pnt pnt1(0, 10, 0); 5 gp_Pnt pnt2(10, 10, 0); 6 gp_Pnt pnt3(10, 0, 0); 7 gp_Pnt pnt4(0, 0, 0); 8 TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(pnt1, pnt2); 9 Geometry::instance()->addShape(ShapeType::Curve, edge1); 10 TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge(pnt2, pnt3); 11 Geometry::instance()->addShape(ShapeType::Curve, edge2); 12 TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge(pnt3, pnt4); 13 Geometry::instance()->addShape(ShapeType::Curve, edge3); 14 TopoDS_Edge edge4 = BRepBuilderAPI_MakeEdge(pnt4, pnt1); 15 Geometry::instance()->addShape(ShapeType::Curve, edge4); 16 17 BRepBuilderAPI_MakeWire wire; 18 wire.Add(edge1); 19 wire.Add(edge2); 20 wire.Add(edge3); 21 wire.Add(edge4); 22 wire.Build(); 23 24 BRepBuilderAPI_MakeFace face(wire); 25 Geometry::instance()->addShape(ShapeType::Surface, face); 26 27 Standard_Real first, last; 28 Handle(Geom_Curve) curve = BRep_Tool::Curve(edge0, first, last); 29 Handle(Geom_TrimmedCurve) trimmedCurve = new Geom_TrimmedCurve(curve, first, last); 30 31 Handle(Geom_Surface) surface = BRep_Tool::Surface(face); 32 33 Handle(Geom_Curve) projCurve = GeomProjLib::Project(trimmedCurve, surface); 34 35 36 37 /** 计算端点投影 */ 38 /*@{*/ 39 gp_Pnt pntFirst(0, 0, 0); 40 gp_Pnt pntLast(10, 10, 10); 41 42 GeomAPI_ProjectPointOnSurf projFirst(pntFirst, surface); 43 GeomAPI_ProjectPointOnSurf projLast(pntLast, surface); 44 45 if (projFirst.NbPoints() != 1 || projLast.NbPoints() != 1 || projFirst.Point(1).Distance(projLast.Point(1)) < Precision::Confusion()) { 46 return; 47 } 48 pntFirst = projFirst.Point(1); 49 pntLast = projLast.Point(1); 50 51 Standard_Real newFirst, newLast; 52 if ( 53 !GeomLib_Tool::Parameter(projCurve, pntFirst, Precision::Confusion(), newFirst) || 54 !GeomLib_Tool::Parameter(projCurve, pntLast, Precision::Confusion(), newLast)) { 55 return; 56 } 57 /*@}*/ 58 59 BRepBuilderAPI_MakeEdge result(projCurve); 60 61 Geometry::instance()->addShape(ShapeType::Curve, result);
标签:10,wire,gp,Curve,OCC,曲线,投影,Pnt,BRepBuilderAPI From: https://www.cnblogs.com/chanyuantiandao/p/18410085