输入:
曲线、曲线上两点
输出
曲线上两点间的曲线
代码:
public bool Test(TopoDS_Shape aS, gp_Pnt ptF, gp_Pnt ptE, ref TopoDS_Shape resShape, double tol = 0.00000001)
{
if (aS.ShapeType() == TopAbs_ShapeEnum.TopAbs_EDGE || aS.ShapeType() == TopAbs_ShapeEnum.TopAbs_WIRE)
{
List<TopoDS_Shape> edges = new List<TopoDS_Shape>();
TopExp_Explorer explor = new TopExp_Explorer(aS, TopAbs_ShapeEnum.TopAbs_EDGE);
while (explor.More())
{
edges.Add(explor.Current());
explor.Next();
}
BRepBuilderAPI_MakeVertex vertex = new BRepBuilderAPI_MakeVertex(ptF);
TopoDS_Vertex vertedx = vertex.Vertex();
BRepBuilderAPI_MakeWire makeWire = new BRepBuilderAPI_MakeWire();
bool isCalf = false;
foreach (var edge in edges)
{
BRepExtrema_DistShapeShape disshapshape = new BRepExtrema_DistShapeShape(edge, vertedx);
if (!disshapshape.IsDone()) continue;
if (disshapshape.Value() > tol) continue;
TopoDS_Edge _edge = TopoDS.ToEdge(edge);
double first = 0.0;
double last = 0.0;
Geom_Curve geom_Curve = BRep_Tool.Curve(_edge, ref first, ref last);
bool CalEndPnt(ref TopoDS_Shape _resShape)
{
if (_resShape == null) _resShape = new TopoDS_Shape();
var lPnt = geom_Curve.Value(last);
var __edge = new BRepBuilderAPI_MakeEdge(geom_Curve, ptF, ptE);
makeWire.Add(__edge.Edge());
makeWire.IsDone();
_resShape.shape = makeWire.Shape();
return true;
}
if (isCalf)
{
var lPnt = geom_Curve.Value(last);
if (lPnt.Distance(ptE) < tol)
{
makeWire.Add(_edge);
if (resShape == null) resShape = new TopoDS_Shape();
makeWire.IsDone();
resShape.shape = makeWire.Shape();
}
else
{
var __edge = new BRepBuilderAPI_MakeEdge(geom_Curve, geom_Curve.Value(first), ptE);
makeWire.Add(__edge.Edge());
makeWire.IsDone();
if (resShape == null) resShape = new TopoDS_Shape();
resShape.shape = makeWire.Shape();
}
return true;
}
else
{
var fPnt = geom_Curve.Value(first);
if (fPnt.Distance(ptF) < tol)
{
vertedx = (new BRepBuilderAPI_MakeVertex(ptE)).Vertex();
disshapshape = new BRepExtrema_DistShapeShape(edge, vertedx);
if (!disshapshape.IsDone() || disshapshape.Value() > tol)
{
makeWire.Add(_edge);
isCalf = true;
continue;
}
return CalEndPnt(ref resShape);
}
else
{
vertedx = (new BRepBuilderAPI_MakeVertex(ptE)).Vertex();
disshapshape = new BRepExtrema_DistShapeShape(edge, vertedx);
if (!disshapshape.IsDone() || disshapshape.Value() > tol)
{
var __edge = new BRepBuilderAPI_MakeEdge(geom_Curve, ptF, geom_Curve.Value(last));
makeWire.Add(__edge.Edge());
continue;
}
return CalEndPnt(ref resShape);
}
}
}
}
return false;
}