private void QuickHull()
        {
            Engine.hull.Clear();
            int min_x = 0, max_x = 0;

            for (int i = 1; i < Engine.points.Count; i++)
            {
                if (Engine.points[i].X < Engine.points[min_x].X)
                {
                    min_x = i;
                }
                if (Engine.points[i].X > Engine.points[max_x].X)
                {
                    max_x = i;
                }
            }
            Engine.hull.Add(Engine.points[min_x]);
            Engine.hull.Add(Engine.points[max_x]);
            Point A = Engine.hull[0];
            Point B = Engine.hull[1];


            {
                myGraphics.gfx.DrawLine(new Pen(Color.Purple), A.X, A.Y, B.X, B.Y);
            }

            List <Point> S1 = new List <Point>();
            List <Point> S2 = new List <Point>();


            foreach (Point point in Engine.points)
            {
                float side = Matematics.FindSide(A, B, point);
                if (side == -1)
                {
                    S1.Add(point);
                }
                side = Matematics.FindSide(B, A, point);
                if (side == -1)
                {
                    S2.Add(point);
                }
            }

            foreach (Point point in S1)
            {
                //point.fillColor = Color.Blue;
                point.fillColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));
                point.draw(myGraphics.gfx);
            }

            foreach (Point point in S2)
            {
                //point.fillColor = Color.Green;
                point.fillColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));
                point.draw(myGraphics.gfx);
            }
            FindHull(S1, A, B);
            FindHull(S2, B, A);
        }
Beispiel #2
0
        private void FindHull(List <Point> sk, Point P, Point Q)
        {
            if (sk.Count == 0)
            {
                return;
            }
            int farthestPointIndex = 0;

            float max_dist = 0;

            for (int i = 0; i < sk.Count; i++)
            {
                float dist = Matematics.lineDist(P, Q, sk[i]);
                if (dist > max_dist)
                {
                    max_dist           = dist;
                    farthestPointIndex = i;
                }
            }

            Point C   = sk[farthestPointIndex];
            int   idx = Engine.hull.IndexOf(P);

            Engine.hull.Insert(idx, C);


            List <Point> S1 = new List <Point>();
            List <Point> S2 = new List <Point>();

            foreach (Point point in Engine.points)
            {
                float side = Matematics.FindSide(P, C, point);
                if (side == -1)
                {
                    S1.Add(point);
                }
                side = Matematics.FindSide(C, Q, point);
                if (side == -1)
                {
                    S2.Add(point);
                }
            }


            FindHull(S1, P, C);
            FindHull(S2, C, Q);
        }
Beispiel #3
0
        private void DivideEtConquer()
        {
            Engine.hull.Clear();
            int min_x = 0, max_x = 0;

            for (int i = 1; i < Engine.points.Count; i++)
            {
                if (Engine.points[i].X < Engine.points[min_x].X)
                {
                    min_x = i;
                }
                if (Engine.points[i].X > Engine.points[max_x].X)
                {
                    max_x = i;
                }
            }
            Engine.hull.Add(Engine.points[min_x]);
            Engine.hull.Add(Engine.points[max_x]);
            Point A = Engine.hull[0];
            Point B = Engine.hull[1];

            List <Point> S1 = new List <Point>();
            List <Point> S2 = new List <Point>();


            foreach (Point point in Engine.points)
            {
                float side = Matematics.FindSide(A, B, point);
                if (side == -1)
                {
                    S1.Add(point);
                }
                side = Matematics.FindSide(B, A, point);
                if (side == -1)
                {
                    S2.Add(point);
                }
            }

            FindHull(S1, A, B);
            FindHull(S2, B, A);
        }