Пример #1
0
        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);
        }
Пример #2
0
        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;
                }
            }
        }