Esempio n. 1
0
        private void bug_Click(object sender, EventArgs e)
        {
            Graphics g = pictureBox1.CreateGraphics();

            g.Clear(Color.White);

            Draw(points, Pens.Red);

            bugs = new IRI.Ket.Geometry.QuasiTriangleCollection();

            if (this.tin != null)
            {
                foreach (IRI.Ket.Geometry.QuasiTriangle item in tin.triangles)
                {
                    IRI.Ket.Geometry.Point p1 = points.GetPoint(item.First);
                    IRI.Ket.Geometry.Point p2 = points.GetPoint(item.Second);
                    IRI.Ket.Geometry.Point p3 = points.GetPoint(item.Third);

                    foreach (IRI.Ket.Geometry.Point p in points)
                    {
                        if (IRI.Ket.Geometry.ComputationalGeometry.GetPointCircleRelation(p, p1, p2, p3) ==
                            IRI.Ket.Geometry.PointCircleRelation.In)
                        {
                            bugs.Add(item);
                            break;
                            //    g.DrawLines(Pens.Green, new Point[]{new Point((int)points.GetPoint(item.First).X,(int)points.GetPoint(item.First).Y),
                            //                            new Point((int)points.GetPoint(item.Second).X,(int)points.GetPoint(item.Second).Y),
                            //                            new Point((int)points.GetPoint(item.Third).X,(int)points.GetPoint(item.Third).Y),
                            //                            new Point((int)points.GetPoint(item.First).X, (int)points.GetPoint(item.First).Y)});
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void checkCircle_Click(object sender, EventArgs e)
        {
            Graphics g = pictureBox1.CreateGraphics();

            g.Clear(Color.White);

            Draw(points, Pens.Black);

            DrawTin(Pens.Blue);

            double x1 = points.GetPoint(tin.triangles[triangleID].First).X; double y1 = points.GetPoint(tin.triangles[triangleID].First).Y;
            double x2 = points.GetPoint(tin.triangles[triangleID].Second).X; double y2 = points.GetPoint(tin.triangles[triangleID].Second).Y;
            double x3 = points.GetPoint(tin.triangles[triangleID].Third).X; double y3 = points.GetPoint(tin.triangles[triangleID].Third).Y;

            //g.DrawLines(Pens.Aqua, new Point[]{new Point((int)points.GetPoint(item.First).X,(int)points.GetPoint(item.First).Y),
            //                                    new Point((int)points.GetPoint(item.Second).X,(int)points.GetPoint(item.Second).Y),
            //                                    new Point((int)points.GetPoint(item.Third).X,(int)points.GetPoint(item.Third).Y),
            //                                    new Point((int)points.GetPoint(item.First).X, (int)points.GetPoint(item.First).Y)});

            double s12 = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
            double s13 = Math.Sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
            double s23 = Math.Sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));

            double s      = (s12 + s13 + s23) / 2;
            float  radius = (float)((s12 * s13 * s23) / (2 * Math.Sqrt(s * (s - s12) * (s - s13) * (s - s23))));

            //g.DrawLine(Pens.Orange, new PointF((float)x1, (float)(pictureBox1.Height - y1)), new PointF((float)center.X, (float)(pictureBox1.Height - center.Y)));

            IRI.Ket.Geometry.Point center =
                IRI.Ket.Geometry.ComputationalGeometry.CalculateCircumcenterCenterPoint(points.GetPoint(tin.triangles[triangleID].First),
                                                                                        points.GetPoint(tin.triangles[triangleID].Second),
                                                                                        points.GetPoint(tin.triangles[triangleID].Third));


            g.DrawEllipse(Pens.Orange, new RectangleF((float)(center.X - radius / 2), (float)(center.Y - radius / 2), (float)radius, (float)radius));

            triangleID = (++triangleID) % this.tin.triangles.Count;
        }
Esempio n. 3
0
        public void Draw(AdjacencyList <IRI.Ket.Geometry.Point, double> network,
                         System.Drawing.Graphics g, System.Drawing.Pen nodePen, System.Drawing.Pen edgePen)
        {
            for (int i = 0; i < network.NumberOfNodes; i++)
            {
                float currentX = (float)network[i].X;

                float currentY = (float)network[i].Y;

                g.DrawEllipse(nodePen, new System.Drawing.RectangleF(currentX - 1, currentY - 1, 2, 2));

                LinkedList <Connection <IRI.Ket.Geometry.Point, double> > temp = network.GetConnectionsByNodeIndex(i);

                foreach (Connection <IRI.Ket.Geometry.Point, double> item in temp)
                {
                    IRI.Ket.Geometry.Point neighbour = item.Node;

                    g.DrawLine(edgePen,
                               new System.Drawing.PointF(currentX, currentY),
                               new System.Drawing.PointF((float)neighbour.X, (float)neighbour.Y));
                }
            }
        }
        public static List <int> GetConvexHullVertexes(PointCollection points)
        {
            int leftBoundIndex = points.LowerBoundIndex;

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

            int length = points.Count;

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

            int counter = 0;

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

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

            list = SortAlgorithm.Heapsort <IndexValue <double> >(list, SortDirection.Descending);

            List <int> result = new List <int>();

            result.Add(leftBoundIndex);

            counter = 0;

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

                if (result.Count < 2)
                {
                    result.Add(list[counter].Index);

                    counter++;

                    continue;
                }

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

                if (pointSituation == PointVectorRelation.LiesLeft)
                {
                    result.Add(list[counter].Index);

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

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

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

            return(result);
        }
        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);
        }