public void Remove() { Next.Last = Last; Last.Next = Next; Next = null; Last = null; }
public Circular Prepend(Circular node) { node.Next = this; node.Last = Last; Last.Next = node; Last = node; return node; }
public Circular Append(Circular node) { node.Last = this; node.Next = Next; Next.Last = node; Next = node; return node; }
public Circular Append(Circular node) { node.Last = this; node.Next = Next; Next.Last = node; Next = node; return(node); }
public Circular Prepend(Circular node) { node.Next = this; node.Last = Last; Last.Next = node; Last = node; return(node); }
public void Duplicate(ref Point3[] Points, int i) { Circular node = this; do { Points[i++] = node.Point; node = node.Next; } while (node != this); }
public static Point3[] getConvexPolygon(Point3[] points) { int num = points.Length; sort(ref points, 0, points.Length - 1); Point3 left = points[0]; Point3 right = points[num - 1]; Circular lower = new Circular(left); Circular upper = new Circular(left); for (int i = 0; i < num; i++) { double result = Point3.check(left, right, points[i]); if (result > 0) { upper = upper.Append(new Circular(points[i])); } else if (result < 0) { lower = lower.Prepend(new Circular(points[i])); } } lower = lower.Prepend(new Circular(right)); upper = upper.Append(new Circular(right)).Next; minimize(lower); minimize(upper); if (lower.Last.Point.Equals(upper.Point)) { lower.Last.Remove(); } if (upper.Last.Point.Equals(lower.Point)) { upper.Last.Remove(); } Point3[] final = new Point3[lower.Length() + upper.Length() + 1]; lower.Duplicate(ref final, 0); upper.Duplicate(ref final, lower.Length()); final[lower.Length() + upper.Length()] = final[0]; increase1pc(ref final); return(final); }
public int Length() { int num = 0; Circular node = this; do { num++; node = node.Next; } while (node != this); return(num); }
private static void minimize(Circular start) { Circular a = start; Circular end = start.Last; bool finished = false; while (a.Next != start || !finished) { if (a.Next == end) { finished = true; } if (Point3.check(a.Point, a.Next.Point, a.Next.Next.Point) < 0) { a = a.Next; } else { a.Next.Remove(); a = a.Last; } } }
public Circular(Point3 point) { Point = point; Next = this; Last = this; }
private static void minimize(Circular start) { Circular a = start; Circular end = start.Last; bool finished = false; while (a.Next != start || !finished) { if (a.Next == end) finished = true; if (Point3.check(a.Point, a.Next.Point, a.Next.Next.Point) < 0) a = a.Next; else { a.Next.Remove(); a = a.Last; } } }
public static Point3[] getConvexPolygon(Point3[] points) { int num = points.Length; sort(ref points,0,points.Length-1); Point3 left = points[0]; Point3 right = points[num - 1]; Circular lower = new Circular(left); Circular upper = new Circular(left); for (int i = 0; i < num; i++) { double result = Point3.check(left, right, points[i]); if (result > 0) upper = upper.Append(new Circular(points[i])); else if (result < 0) lower = lower.Prepend(new Circular(points[i])); } lower = lower.Prepend(new Circular(right)); upper = upper.Append(new Circular(right)).Next; minimize(lower); minimize(upper); if (lower.Last.Point.Equals(upper.Point)) lower.Last.Remove(); if (upper.Last.Point.Equals(lower.Point)) upper.Last.Remove(); Point3[] final = new Point3[lower.Length() + upper.Length() + 1]; lower.Duplicate(ref final, 0); upper.Duplicate(ref final, lower.Length()); final[lower.Length() + upper.Length()] = final[0]; increase1pc(ref final); return final; }