測試結果:ide
主要思路:假設有兩條曲線分別是c1和c2,把c1按照1的距離劃分我這裏用變量jd表示,獲得一個曲線集合coll,而後遍歷coll,獲得coll中每個曲線的兩個端點,再用這兩個端點分別求離曲線c2的最短距離,直接使用開發庫的GetClosestPointTo方法就能夠了,直到遍歷完整個coll集合就能獲得最短距離和其對應的點。測試
主要代碼獲得曲線集合coll:spa
public List<Curve> GetCurves(Curve curve ,double jd) { List<Curve> lstCurves = new List<Curve>(); double totalLength = curve.GetDistanceAtParameter(curve.EndParam); if (totalLength < jd) { lstCurves.Add(curve); return lstCurves; } double addLength = 0; Point3dCollection pt3dCol = new Point3dCollection(); while (addLength < totalLength) { pt3dCol.Add(curve.GetPointAtDist(addLength)); addLength += jd; } if (addLength != totalLength) pt3dCol.Add(curve.GetPointAtDist(totalLength)); DBObjectCollection dbObjColl= curve.GetSplitCurves(pt3dCol); foreach (var item in dbObjColl) { lstCurves.Add((Curve)item); } dbObjColl.Dispose(); return lstCurves; }
主要代碼獲得最短距離和最近點:3d
public Line GetMinLine(Curve curve1,Curve curve2,double jd) { List<Curve> lstCurves = GetCurves(curve1, jd); double minVal = double.MaxValue; Point3d ptMin1 = Point3d.Origin; Point3d ptMin2 = Point3d.Origin; foreach (var c in lstCurves) { Point3d pt1 = c.StartPoint; Point3d pt2 = c.EndPoint; var pt11=curve2.GetClosestPointTo(pt1, false); var pt22= curve2.GetClosestPointTo(pt2, false); var l1 = pt11.DistanceTo(pt1); var l2 = pt22.DistanceTo(pt2); if (l1 < minVal) { minVal = l1; ptMin1 = pt11; ptMin2 = pt1; } if (l2 < minVal) { minVal = l2; ptMin1 = pt22; ptMin2 = pt2; } } ed.WriteMessage("\n最短距離:" + minVal + "\n"); return new Line(ptMin1,ptMin2); }
關於GetClosestPointTo介紹以下:code