/// <summary> /// Add a new vertice in order in the list of vertices of the polygon given the IntersectionResultArray. /// </summary> /// <param name="points"></param> /// <param name="resultArray"></param> /// <param name="curve"></param> private static CircularLinkedListNode <UV> AddPointsInList(CircularLinkedList <UV> points, IntersectionResultArray resultArray, Curve curve) { UV p0 = VectorManipulator.ProjectInPlaneXY(curve.GetEndPoint(0)); CircularLinkedListNode <UV> newNode = null; CircularLinkedListNode <UV> node = FindPoint(points, p0); IntersectionResultArrayIterator iterator = resultArray.ForwardIterator(); iterator.Reset(); while (iterator.MoveNext()) { IntersectionResult result = iterator.Current as IntersectionResult; UV intersectionPoint = VectorManipulator.ProjectInPlaneXY(result.XYZPoint); newNode = points.AddAfter(node, intersectionPoint); } if (newNode.Next.Value.IsAlmostEqualTo(newNode.Value)) { points.Remove(newNode.Next.Value); } else if (newNode.Previous.Value.IsAlmostEqualTo(newNode.Value)) { points.Remove(newNode.Previous.Value); } return(newNode); }
/// <summary> /// Finds a point that /// </summary> /// <param name="points"></param> /// <param name="line1"></param> /// <param name="posibleCurves"></param> /// <returns></returns> private static CircularLinkedListNode <UV> FindNewNode(ref CircularLinkedList <UV> points, Line line, CurveArray posibleCurves, UV notch) { // iterate for each possible curve, and if // a intersection is found, the point will // be added in the linked list CircularLinkedListNode <UV> newNode = null; // get the closest point UV newPoint = null, previousPoint = null; double minDistance = double.MaxValue; foreach (Curve curve in posibleCurves) { SetComparisonResult intersection = curve.Intersect(line, out IntersectionResultArray resultArray); if (intersection == SetComparisonResult.Overlap) { IntersectionResultArrayIterator iterator = resultArray.ForwardIterator(); iterator.Reset(); while (iterator.MoveNext()) { IntersectionResult result = iterator.Current as IntersectionResult; UV point = VectorManipulator.ProjectInPlaneXY(result.XYZPoint); double distance = point.DistanceTo(notch); if (distance < minDistance) { minDistance = distance; newPoint = point; previousPoint = VectorManipulator.ProjectInPlaneXY(curve.GetEndPoint(0)); } } } } // insert the new point in the list CircularLinkedListNode <UV> node = FindPoint(points, previousPoint); newNode = points.AddAfter(node, newPoint); if (newNode.Next.Value.IsAlmostEqualTo(newNode.Value)) { points.Remove(newNode.Next.Value); } else if (newNode.Previous.Value.IsAlmostEqualTo(newNode.Value)) { points.Remove(newNode.Previous.Value); } return(newNode); }
public bool Normalize() { bool normalized = true; CircularLinkedList <UV> points = GetPoints(); CircularLinkedListNode <UV> node = points.Head; do { UV p0 = node.Previous.Value; UV p1 = node.Value; UV p2 = node.Next.Value; double angle = VectorManipulator.CalculatesAngle(p0, p1, p2); if (AlmostEqual(angle, Math.PI, 0.01) || AlmostEqual(angle, 0, 0.01)) { points.Remove(p1); normalized = false; } node = node.Next; } while (node != points.Head); curveArray = CreateCurveArrayFromPoints(points); if (!normalized) { Normalize(); } return(normalized); }