Exemple #1
0
        public Form1()
        {
            InitializeComponent();

            poligon          = new Poligon();
            acoperireConvexa = new Poligon();
        }
Exemple #2
0
        private Poligon UpdateHull(Poligon hull, List <PointF> sortedPoints, int index)
        {
            int hullSize    = hull.GetNumberOfPoints();
            int orientation = OrientationTest(hull.GetPointAt(hullSize - 2), hull.GetPointAt(hullSize - 1), sortedPoints[index]);

            if (orientation == 2)
            {
                hull.AddPoint(sortedPoints[index]);
                Console.Write(sortedPoints[index].X + " " + sortedPoints[index].Y);
            }

            else if (orientation == 1)
            {
                hull.RemovePoint();
                hull.AddPoint(sortedPoints[index]);
                Console.Write(sortedPoints[index].X + " " + sortedPoints[index].Y);
            }

            else
            {
                PointF furthestPoint = HighestY(hull.GetPointAt(hullSize - 1), sortedPoints[index]);
                hull.RemovePoint();
                hull.AddPoint(furthestPoint);
                Console.Write(furthestPoint.X + " " + furthestPoint.Y);
            }

            return(hull);
        }
Exemple #3
0
        public Poligon GenerateHull()
        {
            Poligon hull = new Poligon();

            //  List<PointF> sortedPoints = SortByPolarAngle();
            //// for(int i=0;i<sortedPoints.Count;i++)
            //  //    System.Windows.Forms.MessageBox.Show(sortedPoints[i].X + "    ,    " + sortedPoints[i].Y);

            //  hull.AddPoint(sortedPoints[0]);
            //  hull.AddPoint(sortedPoints[1]);
            //  for (int i = 2; i < sortedPoints.Count; ++i)
            //  {
            //      UpdateHull(hull, sortedPoints, i);
            //  }

            //  int hullSize = hull.GetNumberOfPoints();
            //  int orientation = OrientationTest(hull.GetPointAt(hullSize - 1) ,hull.GetPointAt(0), hull.GetPointAt(1));

            //  if (orientation == 1 || orientation == 0)
            //  {
            //      hull.RemovePoint(0);
            //  }
            //  hull.AddPoint(hull.points[0]);

            int lowestXIndex = GetLowestXIndex();
            int currentIndex = lowestXIndex;

            do
            {
                hull.AddPoint(points[currentIndex]);

                int nextIndex = (currentIndex + 1) % points.Count;
                for (int i = 0; i < points.Count; ++i)
                {
                    if (OrientationTest(points[currentIndex], points[i], points[nextIndex]) == 2)
                    {
                        nextIndex = i;
                    }
                }

                currentIndex = nextIndex;
            } while (currentIndex != lowestXIndex);
            return(hull);
        }
Exemple #4
0
        private void generateBtn_Click(object sender, EventArgs e)
        {
            grafic.Series["Acoperire convexa"].Points.Clear();

            acoperireConvexa = poligon.GenerateHull();
            // MessageBox.Show(acoperireConvexa.GetNumberOfPoints().ToString());
            for (int i = 0; i < acoperireConvexa.GetNumberOfPoints(); ++i)
            {
                double x = acoperireConvexa.GetPointAt(i).X;

                double y = acoperireConvexa.GetPointAt(i).Y;


                grafic.Series["Acoperire convexa"].Points.AddXY(x, y);
                grafic.Series["Puncte acoperire convexa"].Points.AddXY(x, y);
            }

            grafic.Series["Acoperire convexa"].Points.AddXY(acoperireConvexa.GetPointAt(0).X, acoperireConvexa.GetPointAt(0).Y);
        }