コード例 #1
0
        public bool Near(V2 o)
        {
            BigInteger Delta = BigInteger.Abs(o.x - x) + BigInteger.Abs(o.y - y);

            if (Delta < 8)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        //////////////////////////////////////////////////////////////
        //
        //   Cree un ensemble de points aléatoires
        //

        static private void AddPoint(List <V2> LP)
        {
            V2 P = RandomPoint();

            // pour éviter d'insérer un point existant dans la liste
            foreach (V2 PP in LP)
            {
                if (P.Near(PP))
                {
                    return;
                }
            }

            LP.Add(P);
        }
コード例 #3
0
        /* Separation des groupes de point droite */
        static private List <V2> splitSet(V2 mp1, V2 mp2, List <V2> points)
        {
            List <V2> res        = new List <V2>(); // Points restant à traiter.
            V2        mainVector = mp2 - mp1;       // Nouveau coté de l'enveloppe

            foreach (V2 point in points)
            {
                V2         vector  = point - mp1;
                BigInteger prodVec = vector ^ mainVector;
                if (prodVec > 0)
                {
                    res.Add(point);
                }
            }
            return(res);
        }
コード例 #4
0
        static private V2 RandomPoint()
        {
            // uniform
            if (typerandom == 0)
            {
                int Larg = 300;
                int Haut = 300;

                int x = RandP(Larg) + 100;
                int y = RandP(Haut) + 100;
                V2  P = new V2(x, y);
                return(P);
            }

            // spherique
            if (typerandom == 1)
            {
                double t = Ran.NextDouble() * Math.PI * 2;

                double R = 150;

                int x = (int)(R * Math.Cos(t) + R + 50);
                int y = (int)(R * Math.Sin(t) + R + 50);
                V2  P = new V2(x, y);
                return(P);
            }

            // gaussien
            if (typerandom == 2)
            {
                int Larg = 200;
                int Haut = 200;

                int x = (int)(Gaussian() * Larg) + 250;
                int y = (int)(Gaussian() * Haut) + 250;
                V2  P = new V2(x, y);
                return(P);
            }



            return(new V2(0, 0));
        }
コード例 #5
0
        /* Trouve le point le plus proche du vecteur */
        static private V2 findFurthestPoint(V2 mp1, V2 mp2, List <V2> points)
        {
            V2 mainVector    = mp2 - mp1;
            V2 furthestPoint = points[0];

            double maxDistance = distanceFromMainVector(mp1, mainVector, furthestPoint);

            foreach (V2 point in points)
            {
                double distance = distanceFromMainVector(mp1, mainVector, point);
                if (distance > maxDistance)
                {
                    furthestPoint = point;
                    maxDistance   = distance;
                }
            }

            return(furthestPoint);
        }
コード例 #6
0
        static public void start()
        {
            Console.WriteLine("Sart_GiftWrap");

            List <V2> points = SetofPoints.LP;

            convexHull = new List <V2>();

            V2 initPoint = points[0];

            foreach (V2 point in points)
            {
                if (initPoint.x > point.x || (initPoint.x == point.x && initPoint.y > point.y))
                {
                    initPoint = point;
                }
            }

            convexHull.Add(initPoint);
        }
コード例 #7
0
        static private LinkedList <Tuple <Tuple <LinkedListNode <V2>, LinkedListNode <V2> >, List <V2> > > setToProcess; // List pair cote de l'enveloppe et set de point (LinkedListNode pour facilité l'insertion)

        static public void start()
        {
            Console.WriteLine("Start_QuickHull");

            List <V2> points = SetofPoints.LP;

            convexHull   = new LinkedList <V2>();
            setToProcess = new LinkedList <Tuple <Tuple <LinkedListNode <V2>, LinkedListNode <V2> >, List <V2> > >();

            V2 minXPoint = points[0];
            V2 maxXPoint = minXPoint;

            foreach (V2 point in points)
            {
                if (minXPoint.x > point.x || (minXPoint.x == point.x && minXPoint.y > point.y))
                {
                    minXPoint = point;
                }

                if (maxXPoint.x < point.x || (maxXPoint.x == point.x && maxXPoint.y < point.y))
                {
                    maxXPoint = point;
                }
            }

            convexHull.AddFirst(maxXPoint);
            convexHull.AddFirst(minXPoint);

            addSetToSetToPrecess(convexHull.First, convexHull.Last, points);
            addSetToSetToPrecess(convexHull.Last, convexHull.First, points);

            convexHull.AddLast(convexHull.First.Value); // Pour créer la boucle

            Affichage.DrawPolChain(convexHull.ToList <V2>(), Color.Red);
            Affichage.Show();
        }
コード例 #8
0
        /*Retourne la distance d'un point à un droite.
         * firstMainPoint: un point du coté de l'enveloppe traité.
         * mainVector: coté de l'enveloppe correspondant à un droite -> ax + by + c -> V(b; -a)
         */
        static private double distanceFromMainVector(V2 firstMainPoint, V2 mainVector, V2 point)
        {
            double numerator   = (double)BigInteger.Abs(mainVector.x * (firstMainPoint.y - point.y) - mainVector.y * (firstMainPoint.x - point.x));
            double denominator = Math.Sqrt((double)(mainVector.x * mainVector.x + mainVector.y * mainVector.y));

            return(numerator / denominator);
        }
コード例 #9
0
 public V2(V2 t)
 {
     x = t.x;
     y = t.y;
 }
コード例 #10
0
        public bool Equals(V2 other)
        {
            bool eq = ((other.x == x) && (other.y == y));

            return(eq);
        }
コード例 #11
0
        static public void Iteration()
        {
            Console.WriteLine("Iteration_MelkMan");

            List <V2> points = SetofPoints.LP;

            if (currentIndex == points.Count)       // Verifie s'il reste des points à traiter
            {
                return;
            }

            int initialSize = convexHull.Count();   // Taille de l'enveloppe avant ajout d'un nouveau point

            LinkedListNode <V2> first = convexHull.First;
            LinkedListNode <V2> last  = convexHull.Last;
            V2 leftVector             = first.Next.Value - first.Value;   // Vecteur à gauche du dernier point
            V2 rightVector            = last.Previous.Value - last.Value; // Vecteur à droite du dernier point

            bool again = true;

            while (again && currentIndex != points.Count)    // On parcours les points de l'essemble LP tant qu'un point n'a pas été ajouté à l'enveloppe et que tous n'ont pas été parcouru.
            {
                Console.WriteLine("CurrentIndex_Iteration");

                V2 tempLeftVector  = points[currentIndex] - first.Value; // Vecteur à comparer à leftVector
                V2 tempRightVector = points[currentIndex] - last.Value;  // Vecteur à comparer à rightVector

                BigInteger prodVecLeft  = tempLeftVector ^ leftVector;
                BigInteger prodVecRight = tempRightVector ^ rightVector;

                if (prodVecLeft < 0 || prodVecRight > 0)
                {
                    while (prodVecLeft < 0)     // Tant que le nouveau point peut être placé à gauche
                    {
                        convexHull.RemoveFirst();
                        first          = convexHull.First;
                        leftVector     = first.Value - first.Next.Value;
                        tempLeftVector = first.Value - points[currentIndex];
                        prodVecLeft    = tempLeftVector ^ leftVector;
                    }
                    convexHull.AddFirst(points[currentIndex]);

                    while (prodVecRight > 0) // Tant que le nouveau point peut être placé à droite
                    {
                        convexHull.RemoveLast();
                        last            = convexHull.Last;
                        rightVector     = last.Value - last.Previous.Value;
                        tempRightVector = last.Value - points[currentIndex];
                        prodVecRight    = tempRightVector ^ rightVector;
                    }
                    convexHull.AddLast(points[currentIndex]);
                    again = false;
                }
                currentIndex++;
            }

            /* Draw */
            Affichage.RefreshScreen();
            Affichage.DrawSet(SetofPoints.LP, Color.Blue);
            Affichage.DrawPolChain(SetofPoints.LP, Color.Green);
            Affichage.DrawPolChain(convexHull.ToList <V2>(), Color.Red);
            Affichage.Show();
        }