示例#1
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);
        }
示例#2
0
        private void grafic_MouseClick(object sender, MouseEventArgs e)
        {
            if (numberOfClicks++ == 0)
            {
                grafic.Series["Puncte poligon"].Points.Clear();
            }

            double x = grafic.ChartAreas[0].AxisX.PixelPositionToValue(e.X);
            double y = grafic.ChartAreas[0].AxisY.PixelPositionToValue(e.Y);

            if (ClickOutsideChartArea(x, y) == false)
            {
                grafic.Series["Puncte poligon"].Points.AddXY(x, y);
                poligon.AddPoint(new PointF((float)x, (float)y));
            }
        }
示例#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);
        }