public static IPolyLine3D TrimmedRegion(Matrix44 lcs, IPolyLine3D trimmedRegion, IPolyLine3D trimRegion, out bool done) { done = false; List <IPoint3D> listOfIntersectionPoint = new List <IPoint3D>(); Intersect(trimmedRegion, trimRegion, listOfIntersectionPoint); if (listOfIntersectionPoint.Count > 0) { done = true; IPolyLine3D trimmedRegionCopy = new PolyLine3D(trimmedRegion); IPolyLine3D trimRegionCopy = new PolyLine3D(trimRegion); IPolyLine2D trimmedPolyLine2D = ConvertTo2D(lcs, trimmedRegionCopy); IPolyLine2D trimPolyLine2D = ConvertTo2D(lcs, trimRegionCopy); Region2D trimmedRegion2D = new Region2D(trimmedPolyLine2D); Region2D trimRegion2D = new Region2D(trimPolyLine2D); // odecte od "trimmedRegion2D" "trimRegion2D". var clipper = new ClipperController(trimmedRegion2D, trimRegion2D); IRegion2D[] regions = clipper.Difference().ToArray(); if (regions.Length > 0) { IPolyLine3D adaptedRegion = ConvertTo3D(regions[0].Outline); TransformToGCS(lcs, adaptedRegion); return(adaptedRegion); } } return(trimmedRegion); }
/// <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); }
/// <summary> /// Remove a opening from collection /// </summary> /// <param name="opening">The opening to be deleted</param> public void RemoveOpening(IPolyLine3D opening) { if (openings.Remove(opening)) { UnsubscribeEvents(opening); } }
internal static IPolygon2D ToPolygon2D(IPolyLine3D polyline3D, IMatrix44 lcs, int numberOfArcTiles) { var polyline = ConvertTo2D(polyline3D, lcs); var polygon = ToPolygon2D(polyline, numberOfArcTiles); return(polygon); }
/// <summary> /// creates a polyline from another polyline /// </summary> /// <param name="source">Source polyline</param> public PolyLine3D(IPolyLine3D source) { if (source != null) { Name = (source as ElementBase).Name; segments = new List <ISegment3D>(); if (source.Segments != null) { IPoint3D point = null; foreach (ISegment3D segment in source.Segments) { ISegment3D seg = segment.CloneSegment(); if (point != null) { seg.StartPoint = point; } point = seg.EndPoint; Add(seg); } if (source.IsClosed && segments.Count > 0) { segments[segments.Count - 1].EndPoint = segments[0].StartPoint; } } } }
public static Polygon3D Convert(IPolyLine3D polyline) { var points = new List <IPoint3D>(polyline.Count); GeomOperation.ConvertPolylineToPointList(polyline, points, false, 5); var polygon = new Polygon3D(points.Select(p => p.ToMediaPoint())); return(polygon); }
/// <summary> /// Transforms given polyline 3D to LCS using matrix and converts to 2D geometry. /// </summary> /// <param name="polyline3D">Polyline to convert.</param> /// <param name="lcs">Local coordinate system.</param> /// <returns>2D geometry.</returns> public static IPolyLine2D ConvertTo2D(IPolyLine3D polyline3D, IMatrix44 lcs) { var polylineCopy = new PolyLine3D(polyline3D); GeomOperation.TransformToLCS(lcs, polylineCopy); var polyline2D = ConvertTo2D(polylineCopy); return(polyline2D); }
/// <summary> /// Unsubscribe Events From given polyline /// </summary> protected void UnsubscribeEvents(IPolyLine3D geometry) { //ElementBase element = geometry as ElementBase; //if (element == null) //{ // return; //} ////element.ObjectChanged -= new ObjectChangedEventHandler(OnGeometryChanged); ////element.ObjectLinked -= new ObjectLinkedEventHandler(OnObjectLinked); //PropertyChangedEventManager.RemoveListener(element, this); }
/// <summary> /// Sets the given opening at the specified index /// </summary> /// <param name="index">The zero based index of the opening to get or set</param> /// <param name="opening">The opening to be set at the specified index</param> /// <returns>True if the opening is set correctly /// False otherwise</returns> public bool SetOpeningAt(int index, IPolyLine3D opening) { if (index < 0 || index >= opening.Count) { return(false); } UnsubscribeEvents(openings[index]); openings[index] = opening; SubscribeEvents(openings[index]); return(true); }
public static double GetLengthOfSmallestArcSegment(IPolyLine3D polyLine) { double length = 0.0; bool isFirst = true; foreach (ISegment3D segment in polyLine.Segments) { if (segment is ArcSegment3D) { if (isFirst) { length = GetLength(segment); isFirst = false; } else { length = Math.Min(length, GetLength(segment)); } } } return(length); }
public static double GetRadiusOfSmallestArcSegment(IPolyLine3D polyline) { double radius = 0.0; bool isFirst = true; foreach (ISegment3D segment in polyline.Segments) { var arc = segment as ArcSegment3D; if (arc != null) { if (isFirst) { radius = GetRadius(arc); isFirst = false; } else { radius = Math.Min(radius, GetRadius(arc)); } } } return(radius); }
internal static IPolyLine2D ConvertTo2D(IPolyLine3D polyline3D) { IPolyLine2D polyline2D = new PolyLine2D(); foreach (ISegment3D segment3D in polyline3D.Segments) { var segment2D = ConvertTo2D(segment3D); if (segment2D != null) { polyline2D.Segments.Add(segment2D); } } if (polyline3D.IsClosed) { polyline2D.StartPoint = new IdaComPoint2D(polyline2D.Segments[polyline2D.Segments.Count - 1].EndPoint.X, polyline2D.Segments[polyline2D.Segments.Count - 1].EndPoint.Y); } else { polyline2D.StartPoint = new IdaComPoint2D(polyline3D[0].StartPoint.X, polyline3D[0].StartPoint.Y); } return(polyline2D); }
/// <summary> /// Calculate inner partial polyline by intersecting region and polyline /// </summary> /// <param name="region">IRegion3D</param> /// <param name="innerPolyline">Polyline3D used to calculate inner partial polyline</param> /// <param name="innerPolylineList">List of inner partial polyline prepared from the given polygon and polyline</param> /// <returns>IntersectionResults</returns> public static IntersectionResults Intersect(IRegion3D region, IPolyLine3D innerPolyline, ICollection <IPolyLine3D> innerPolylineList) { if (region == null || innerPolyline == null || innerPolylineList == null) { return(IntersectionResults.Undefined); } IPolyLine3D outerPolyline = region.Outline; List <IPoint3D> listOfIntersectionPoint = new List <IPoint3D>(); Intersect(outerPolyline, innerPolyline, listOfIntersectionPoint); foreach (IPolyLine3D opening in region.Openings) { Intersect(opening, innerPolyline, listOfIntersectionPoint); } if (listOfIntersectionPoint.Count < 1) { IPoint3D point = GetPointOnPolyLine(innerPolyline, 0.5); return(IsPointOn(region, point)); } SortedSet <double> relativePositionSet = new SortedSet <double>(); relativePositionSet.Add(0); relativePositionSet.Add(1); foreach (IPoint3D point in listOfIntersectionPoint) { double relativePosition = 0; if (GetRelativePosition(innerPolyline, point, ref relativePosition)) { if (!relativePositionSet.Contains(relativePosition)) { relativePositionSet.Add(relativePosition); } } } IList <ISegment3D> splittedSegments = SplitPolyline(innerPolyline, relativePositionSet); if (splittedSegments == null) { return(IntersectionResults.Undefined); } IntersectionResults interSectionResult = IntersectionResults.Undefined; foreach (ISegment3D segment in splittedSegments) { IPoint3D point = new Point3D(); if (GetPointOnSegment(segment, 0.5, ref point)) { IntersectionResults result = IsPointOn(region, point); interSectionResult |= result; if (result == IntersectionResults.Inside || result == IntersectionResults.OnBorderCurve) { IPolyLine3D polyline = new PolyLine3D(); if (innerPolylineList.Count < 1) { polyline.Add(segment); } else { IPolyLine3D existingPolyline = innerPolylineList.Last(); if (existingPolyline.Count < 1) { polyline.Add(segment); } else { if (existingPolyline.Count > 1) { ISegment3D lastSegment = existingPolyline.Segments.Last(); if (lastSegment.EndPoint.Equals(segment.StartPoint)) { polyline = existingPolyline; } } polyline.Add(segment); } } if (!innerPolylineList.Contains(polyline)) { innerPolylineList.Add(polyline); } } } } if (innerPolylineList.Count < 1) { return(IntersectionResults.OnBorderNode | IntersectionResults.Outside); } return(interSectionResult); }
/// <summary> /// Convert the points of polyline based on baseGeometry /// </summary> /// <param name="matrix">LCS matrix of baseGeometry</param> /// <param name="baseGeometry">Based on this region, the given polyline is modifed</param> /// <param name="polyline">Input polyline object</param> /// <param name="modifyInput">If true, given polyline object is modified. Otherwise prepare new polyline object</param> /// <returns>Polyline object which is based on baseGeometry</returns> public static IPolyLine3D GetPolylineOnRegion(IMatrix44 matrix, IRegion3D baseGeometry, IPolyLine3D polyline, bool modifyInput = true) { if (baseGeometry == null || polyline == null) { return(null); } if (matrix == null) { matrix = GetMatrixPlane(baseGeometry); } if (!modifyInput) { polyline = new PolyLine3D(polyline); } bool isIndependent = true; if (polyline.IsClosed) { isIndependent = false; } ISegment3D firstSegment = null; IPoint3D lastEndPoint = null; foreach (ISegment3D segment in polyline.Segments) { GetSegmentOnRegion(matrix, baseGeometry, segment, isIndependent); if (lastEndPoint != null) { segment.StartPoint = lastEndPoint; } if (firstSegment == null) { firstSegment = segment; } lastEndPoint = segment.EndPoint; isIndependent = false; } if (firstSegment != null && lastEndPoint != null) { firstSegment.StartPoint = lastEndPoint; } return(polyline); }
/// <summary> /// Add a opening to collection /// </summary> /// <param name="opening">New opening to be added</param> public void AddOpening(IPolyLine3D opening) { SubscribeEvents(opening); openings.Add(opening); }