Exemplo n.º 1
0
        private void DrawConvexHull(Pen p)
        {
            try
            {
                int i = points.Count;
            }
            catch
            {
                return;
            }

            IRI.Ket.Geometry.PointCollection c = IRI.Ket.Geometry.ComputationalGeometry.CreateConvexHull(points);

            Graphics g = pictureBox1.CreateGraphics();

            g.DrawEllipse(p, new Rectangle((int)c[0].X - 2, (int)(c[0].Y) - 2, 4, 4));

            for (int i = 0; i < c.Count; i++)
            {
                int j = (i + 1) % c.Count;

                int x1 = (int)c[i].X;

                int y1 = (int)(c[i].Y);

                int x2 = (int)c[j].X;

                int y2 = (int)(c[j].Y);

                g.DrawEllipse(p, new Rectangle(x2 - 2, y2 - 2, 4, 4));

                g.DrawLine(p, new Point(x1, y1), new Point(x2, y2));
            }
        }
Exemplo n.º 2
0
        private void Draw(IRI.Ket.Geometry.PointCollection c, Pen p)
        {
            Graphics g = pictureBox1.CreateGraphics();

            //int index = 0;

            foreach (IRI.Ket.Geometry.Point item in c)
            {
                int x = (int)item.X;

                int y = (int)item.Y;

                g.DrawEllipse(p, new Rectangle(x - 2, y - 2, 4, 4));

                //g.DrawString(index.ToString(), new Font(FontFamily.GenericSansSerif, 5), Brushes.Black, (float)(x + 2.5), (float)(y - 1));

                //index++;
            }

            int x1 = (int)c[c.LowerBoundIndex].X;

            int y1 = (int)c[c.LowerBoundIndex].Y;

            g.DrawEllipse(Pens.Red, new Rectangle(x1 - 2, y1 - 2, 4, 4));
        }
Exemplo n.º 3
0
        private void generate_Click(object sender, EventArgs e)
        {
            Random r = new Random(); Random r2 = new Random(3); Random r3 = new Random(2);

            IRI.Ket.DigitalTerrainModeling.AttributedPointCollection ps = new IRI.Ket.DigitalTerrainModeling.AttributedPointCollection();
            int n = int.Parse(textBox1.Text);

            double[] east  = new double[n];
            double[] north = new double[n];
            double[] value = new double[n];
            for (int i = 0; i < n; i++)
            {
                IRI.Ket.DigitalTerrainModeling.AttributedPoint point = new IRI.Ket.DigitalTerrainModeling.AttributedPoint(r.Next(50, 550), r2.Next(50, 550), r3.Next(-200, 200));

                //if (!ps.Contains(new IRI.Ket.Geometry.Point(point.X, point.Y)))
                //{
                ps.Add(point);
                //}
            }
            this.points = ps;

            IRI.Ket.DigitalTerrainModeling.IrregularDtm dtm = new IRI.Ket.DigitalTerrainModeling.IrregularDtm(ps);

            this.network             = dtm.GetSlopeGraph();
            this.minimumSpanningTree = IRI.Ket.Graph.MinimumSpanningTree.CalculateByKruskal <IRI.Ket.Geometry.Point, double>(this.network);
            //this.tin = new IRI.Ket.Geometry.DelaunayTriangulation(points);
            generateValues();
            //DrawTin(Pens.Black, Pens.Blue);
        }
Exemplo n.º 4
0
        private void checkConvexHull()
        {
            Graphics g = pictureBox1.CreateGraphics(); g.Clear(Color.White);
            Random   r = new Random(); Random r2 = new Random(3);
            List <IRI.Ket.Geometry.Point> collection = new List <IRI.Ket.Geometry.Point>();
            int n = int.Parse(textBox1.Text);

            for (int i = 0; i < n; i++)
            {
                collection.Add(new IRI.Ket.Geometry.Point(r.Next(500), r2.Next(500)));
            }
            IRI.Ket.Geometry.PointCollection points = new IRI.Ket.Geometry.PointCollection(collection);
            Draw(points, Pens.Black);
            //IRI.Ket.Geometry.PointCollection c = IRI.Ket.Geometry.ComputationalGeometry.CreateConvexHull(collection);0
            List <int> result = IRI.Ket.Geometry.ComputationalGeometry.GetConvexHullVertexes(points);

            for (int i = 1; i < result.Count - 1; i++)
            {
                int x1 = (int)points[result[i - 1]].X;
                int y1 = (int)points[result[i - 1]].Y;
                int x2 = (int)points[result[i]].X;
                int y2 = (int)points[result[i]].Y;
                g.DrawLine(Pens.Orange, x1, y1, x2, y2);
            }

            g.DrawLine(Pens.Orange,
                       (int)points[result[result.Count - 1]].X,
                       (int)points[result[result.Count - 1]].Y,
                       (int)points[result[0]].X,
                       (int)points[result[0]].Y);

            //DrawConvexHull(result, Pens.Orange);
        }
Exemplo n.º 5
0
        private void import_Click(object sender, EventArgs e)
        {
            this.points = new IRI.Ket.Geometry.PointCollection();

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "*.txt|*.txt";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(dialog.FileName);

                while (!reader.EndOfStream)
                {
                    string[] temp = (reader.ReadLine()).Split(';');

                    this.points.Add(new IRI.Ket.Geometry.Point(double.Parse(temp[0]), double.Parse(temp[1])));
                }

                reader.Close();

                generateValues();
            }
        }
        public static PointCollection CreateConvexHull(PointCollection points)
        {
            int leftBoundIndex = points.LowerBoundIndex;

            IRI.Ket.Geometry.Point initialPoint = points[leftBoundIndex];

            int length = points.Count;

            IndexValue <double>[] unsortedPoints = new IndexValue <double> [length - 1];

            int counter = 0;

            for (int i = 0; i < length; i++)
            {
                if (i == leftBoundIndex)
                {
                    continue;
                }

                unsortedPoints[counter] = new IndexValue <double>(i,
                                                                  Math.Atan2(points[i].Y - initialPoint.Y,
                                                                             points[i].X - initialPoint.X));
                counter++;
            }

            IndexValue <double>[] sortedPoints = SortAlgorithm.Heapsort <IndexValue <double> >(unsortedPoints, SortDirection.Descending);

            IRI.Ket.Geometry.PointCollection result = new IRI.Ket.Geometry.PointCollection();

            result.Add(points[leftBoundIndex]);

            counter = 0;

            while (counter < sortedPoints.Length)
            {
                IRI.Ket.Geometry.Point tempPoint = points[sortedPoints[counter].Index];

                if (result.Count < 2)
                {
                    result.Add(tempPoint);

                    counter++;

                    continue;
                }

                PointVectorRelation pointSituation = GetPointVectorRelation(tempPoint, result[result.Count - 2], result[result.Count - 1]);

                if (pointSituation == PointVectorRelation.LiesLeft)
                {
                    result.Add(tempPoint);

                    counter++;
                }
                else if (pointSituation == PointVectorRelation.LiesRight)
                {
                    result.RemoveAt(result.Count - 1);
                }
                else
                {
                    if (sortedPoints[counter].Value == sortedPoints[0].Value)
                    {
                        if (CalculateDistance(initialPoint, tempPoint) > CalculateDistance(initialPoint, result[result.Count - 1]))
                        {
                            result.Add(tempPoint);
                        }

                        counter++;
                    }
                    else if (sortedPoints[counter].Value == sortedPoints[length - 2].Value)
                    {
                        if (CalculateDistance(initialPoint, tempPoint) < CalculateDistance(initialPoint, result[result.Count - 1]))
                        {
                            result.Add(tempPoint);
                        }

                        counter++;
                    }
                    else
                    {
                        result.RemoveAt(result.Count - 1);
                    }
                }
            }

            return(result);
        }