Ejemplo n.º 1
0
        static public void Iteration()
        {
            if (setToProcess.Count == 0)    // Tant qu'il y a des ensembles de point à traiter
            {
                return;
            }

            Console.WriteLine("Iteration_QuickHull");

            Tuple <Tuple <LinkedListNode <V2>, LinkedListNode <V2> >, List <V2> > pairToProcess = setToProcess.First(); // Récupération du coté et des points à traiter.
            Tuple <LinkedListNode <V2>, LinkedListNode <V2> > pointsMainVector = pairToProcess.Item1;                   // Récupération des points composant le coté.
            List <V2> points = pairToProcess.Item2;                                                                     // Récupération de l'ensemble où peut être le nouveau point

            V2 furthestPoint = findFurthestPoint(pointsMainVector.Item1.Value, pointsMainVector.Item2.Value, points);   // Point le plus éloigner de la droite.

            LinkedListNode <V2> furtherPointNode = convexHull.AddAfter(pointsMainVector.Item1, furthestPoint);          // Ajout du point entre les points délimitant le coté.

            setToProcess.RemoveFirst();

            addSetToSetToPrecess(furtherPointNode, pointsMainVector.Item2, points);     // Ajout d'un nouveau set à traiter et coté.
            addSetToSetToPrecess(pointsMainVector.Item1, furtherPointNode, points);

            /* Draw */
            Affichage.RefreshScreen();
            Affichage.DrawSet(SetofPoints.LP, Color.Blue);
            //Affichage.DrawPolChain(SetofPoints.LP, Color.Green);
            Affichage.DrawPolChain(convexHull.ToList <V2>(), Color.Red);
            Affichage.Show();
        }
Ejemplo n.º 2
0
        static public void start()
        {
            Console.WriteLine("Sart_MelkMan");

            List <V2> points       = SetofPoints.LP;
            List <V2> toSortPoints = new List <V2>();         // Utiliser pour trier les points dans le sens horaire (1 scénario probleme d'ordre)

            /*for (int i = 0; i < 3; ++i)
             *  HP.AddLast(points[i]);*/

            for (int i = 0; i < 3; ++i)
            {
                toSortPoints.Add(points[i]);
            }

            toSortPoints = toSortPoints.OrderBy(point => point.x).ThenBy(point => point.y).ToList <V2>();    // Trie

            convexHull = new LinkedList <V2>(toSortPoints);
            convexHull.AddLast(convexHull.First());         // Copie du premier en dernier pour simuler la structure de boucle

            currentIndex = 3;

            Affichage.DrawPolChain(convexHull.ToList <V2>(), Color.Red);
            Affichage.Show();
        }
Ejemplo n.º 3
0
        static public void Iteration()
        {
            Console.WriteLine("Iteration_GiftWrap");

            if (convexHull.Count != 1 && convexHull[0].Equals(convexHull.Last()))
            {
                return;
            }

            V2        lastPoint     = convexHull.Last();  // Dernier point du contour.
            List <V2> points        = SetofPoints.LP;
            V2        leftmostPoint = points[0];          // Nouveau point supposer pour le contour.

            for (int i = 1; i < points.Count; ++i)
            {
                V2 leftmostVector = leftmostPoint - lastPoint;        // Vecteur supposé le plus à gauche.
                V2 tempVector     = points[i] - lastPoint;            // Vecteur à tester.

                BigInteger prodVec = leftmostVector ^ tempVector;
                if (leftmostPoint.Equals(lastPoint) || prodVec > 0 || (prodVec == 0 && (leftmostVector.Norme2() < tempVector.Norme2())))
                {
                    leftmostPoint = points[i];
                }
            }
            convexHull.Add(leftmostPoint);                // Ajout à l'enveloppe.

            Affichage.DrawPolChain(convexHull, Color.Red);
            Affichage.Show();
        }
Ejemplo n.º 4
0
        public static void ScenarioTest()
        {
            Scenario.GetScenario(LP);

            // affichage
            Affichage.RefreshScreen();
            Affichage.DrawSet(LP, Color.Blue);
            Affichage.DrawPolChain(LP, Color.Green);
            Affichage.Show();
        }
Ejemplo n.º 5
0
        public static void RandomTest()
        {
            // creation d'une liste de points

            Scenario.CreateRandomPoint(LP, 30);

            // affichage
            Affichage.RefreshScreen();
            Affichage.DrawSet(LP, Color.Blue);
            Affichage.Show();
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
 public Form1()
 {
     InitializeComponent();
     pictureBox1.Image = Affichage.Init(pictureBox1.Width, pictureBox1.Height);
 }
Ejemplo n.º 8
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();
        }