/// <summary> /// Returns mininum distance between regions /// </summary> /// <param name="inner"></param> /// <param name="outer"></param> /// <returns></returns> public static double GetDistanceBetweenPolylines3D(IPolyLine3D inner, IPolyLine3D outer) { IList <IPoint3D> innerPoints = inner.Segments.Select(s => s.StartPoint).ToList(); IList <ISegment3D> outerSegments = outer.Segments.ToList(); double minDistance = double.MaxValue; Point3D intersection = new Point3D(); foreach (var innerPoint in innerPoints) { Plane3D tempPlane = new Plane3D { PointOnPlane = new WM.Point3D(innerPoint.X, innerPoint.Y, 0) }; foreach (var outerSegment in outerSegments) { tempPlane.NormalVector = outerSegment.GetDirection(); if (outerSegment is ILineSegment3D) { intersection = new Point3D(tempPlane.GetIntersection(outerSegment as ILineSegment3D)); } var vect = intersection - (innerPoint as Point3D); var tempDist = vect.Magnitude; minDistance = Math.Min(minDistance, tempDist); } } return(minDistance); }
public override IList <Polyline4D> Clip(Polyline4D polyline, bool filled) { int count = polyline.Count; switch (count) { case 0: return(AbstractClipperBase4D.PolylinesClippedAway); case 1: if (!Class455.Contains(this.class461_0, this.matrix4D_1.TransformToPoint2D(polyline[0]))) { return(AbstractClipperBase4D.PolylinesClippedAway); } return((IList <Polyline4D>) new Polyline4D[1] { polyline }); default: Polyline3D polyline1 = new Polyline3D(polyline.Count, polyline.Closed); foreach (Vector4D vector in (List <Vector4D>)polyline) { polyline1.Add(this.matrix4D_1.TransformToPoint3D(vector)); } Class455.Class462 polylineInfo = new Class455.Class462(polyline1); List <Class455.Class456> class456List = this.class461_0.method_0((Class455.Class460)polylineInfo); if (class456List.Count == 0) { if (polyline1.Count == 0) { return (IList <Polyline4D>) new Polyline4D[1] { polyline } } ; foreach (Point3D point3D in (List <Point3D>)polyline1) { if (Class455.Contains(this.class461_0, (Point2D)point3D)) { return (IList <Polyline4D>) new Polyline4D[1] { polyline } } ; } if (!filled || polyline.Count < 3) { return(AbstractClipperBase4D.PolylinesClippedAway); } Polygon2D polygon2D = new Polygon2D(polyline1.Count); foreach (Point3D point3D in (List <Point3D>)polyline1) { polygon2D.Add((Point2D)point3D); } bool flag = false; foreach (Point2D p in (List <Point2D>) this.class461_0.polygon2D_0) { if (polygon2D.IsInside(p)) { flag = true; break; } } if (filled && flag) { Plane3D?plane = Polygon3D.GetPlane((IList <Point3D>)polyline1); if (plane.HasValue) { Plane3D plane3D = plane.Value; Polyline4D polyline4D = new Polyline4D(this.class461_0.polygon2D_0.Count, true); foreach (Point2D point2D in (List <Point2D>) this.class461_0.polygon2D_0) { Point3D?intersection = plane3D.GetIntersection(new Ray3D(point2D.X, point2D.Y, 0.0, 0.0, 0.0, 1.0)); if (intersection.HasValue) { polyline4D.Add(this.matrix4D_0.TransformTo4D(intersection.Value)); } else { intersection = plane3D.GetIntersection(new Ray3D(point2D.X, point2D.Y, 0.0, 0.0, 0.0, -1.0)); if (intersection.HasValue) { polyline4D.Add(this.matrix4D_0.TransformTo4D(intersection.Value)); } } } return((IList <Polyline4D>) new Polyline4D[1] { polyline4D }); } } return(AbstractClipperBase4D.PolylinesClippedAway); } bool flag1 = polylineInfo.double_0 * this.class461_0.double_0 >= 0.0; List <Polyline4D> polyline4DList = new List <Polyline4D>(); int index1; if (!Class455.Contains(this.class461_0, (Point2D)polyline1[0])) { index1 = 0; } else if (polyline.Closed) { index1 = class456List.Count - 1; } else { Polyline4D result = new Polyline4D(filled); this.method_0(result, 0.0, class456List[0].double_1, polylineInfo); polyline4DList.Add(result); class456List.RemoveAt(0); index1 = 0; if (class456List.Count == 0) { return((IList <Polyline4D>)polyline4DList); } } if (filled) { while (class456List.Count > 0) { if (polylineInfo.bool_0) { class456List.Sort(new Comparison <Class455.Class456>(Class455.Class456.smethod_2)); } else { class456List.Sort(new Comparison <Class455.Class456>(Class455.Class456.smethod_0)); if (!flag1) { class456List.Reverse(); } } for (int index2 = 0; index2 < class456List.Count; ++index2) { Class455.Class456 class456_1 = class456List[index2]; Class455.Class456 class456_2 = class456List[(index2 + 1) % class456List.Count]; class456_1.class456_0 = class456_2; class456_2.class456_1 = class456_1; } class456List.Sort(new Comparison <Class455.Class456>(Class455.Class456.smethod_1)); for (int index2 = 0; index2 < class456List.Count; ++index2) { Class455.Class456 class456_1 = class456List[index2]; Class455.Class456 class456_2 = class456List[(index2 + 1) % class456List.Count]; class456_1.class456_2 = class456_2; class456_2.class456_3 = class456_1; } Polyline4D result = new Polyline4D(true); polyline4DList.Add(result); Class455.Class456 class456 = class456List[index1]; class456List.RemoveAt(index1); bool flag2 = index1 > 0; index1 = 0; Class455.Class456 start = class456; do { Class455.Class456 end = start.class456_2; bool flag3; if (flag2 || end.double_1 >= start.double_1) { double parameter = 0.5 * (start.double_1 + end.double_1); if (flag2) { parameter += 0.5 * (double)count; flag2 = false; } flag3 = Class455.Contains(this.class461_0, (Point2D)Class455.smethod_1(polylineInfo.polyline3D_0, parameter)); } else { goto label_72; } label_65: if (flag3) { this.method_0(result, start.double_1, end.double_1, polylineInfo); } else { end = start.class456_0; if (polylineInfo.bool_0) { result.Add(this.matrix4D_0.TransformTo4D(Class455.smethod_1(polylineInfo.polyline3D_0, start.double_1))); } else { this.method_1(result, start, end, !flag1, polylineInfo); } } class456List.Remove(end); if (end.class456_2 != end.class456_3) { end.class456_1.class456_0 = end.class456_0; end.class456_0.class456_1 = end.class456_1; end.class456_3.class456_2 = end.class456_2; end.class456_2.class456_3 = end.class456_3; start = end; continue; } break; label_72: flag3 = false; goto label_65; }while (!object.ReferenceEquals((object)start, (object)class456)); if (result.Count < 3) { result.Closed = false; } } } else { bool flag2 = Class455.Contains(this.class461_0, (Point2D)polyline1[polyline1.Count - 1]); class456List.Sort(new Comparison <Class455.Class456>(Class455.Class456.smethod_1)); Class455.Class456 class456_1 = class456List[index1]; class456List.RemoveAt(index1); while (class456List.Count > 0) { Class455.Class456 class456_2 = class456List[0]; class456List.RemoveAt(0); double parameter = 0.5 * (class456_1.double_1 + class456_2.double_1); if (class456_2.double_1 < class456_1.double_1) { parameter += 0.5 * (double)count; } if (Class455.Contains(this.class461_0, (Point2D)Class455.smethod_1(polylineInfo.polyline3D_0, parameter))) { Polyline4D result = new Polyline4D(); this.method_0(result, class456_1.double_1, class456_2.double_1, polylineInfo); polyline4DList.Add(result); } class456_1 = class456_2; } if (!polyline.Closed && flag2) { Polyline4D result = new Polyline4D(); this.method_0(result, class456_1.double_1, (double)(polyline.Count - 1), polylineInfo); polyline4DList.Add(result); } } return((IList <Polyline4D>)polyline4DList); } }