Beispiel #1
0
        public PointPolygonRelation GetRelationTo(Point point)
        {
            int count = this.Count;

            int tempValue = 0;

            PointVectorRelation[] relation = new PointVectorRelation[count];

            for (int i = 0; i < count; i++)
            {
                int j = (i + 1) % count;

                relation[i] = ComputationalGeometry.GetPointVectorRelation(point, Vertexes[i], Vertexes[j]);

                tempValue += (int)relation[i];

                if ((i > 0 && (int)relation[i] * (int)relation[i - 1] < 1))
                {
                    return(PointPolygonRelation.Out);
                }
            }

            if (tempValue == count || tempValue == (-1 * count))
            {
                return(PointPolygonRelation.In);
            }
            else
            {
                return(PointPolygonRelation.On);
            }
        }
Beispiel #2
0
        private List <int> GetAffectedPolygons(VoronoiCell polygon, List <Point> newVertexes, List <int> edgeIndexes)
        {
            PointVectorRelation relation = ComputationalGeometry.GetPointVectorRelation(polygon.PrimaryPoint, newVertexes[0], newVertexes[1]);

            if (relation == PointVectorRelation.LiesOnTheLine)
            {
                throw new NotImplementedException();
            }

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

            bool condition = false;

            for (int i = 0; i < polygon.Vertexes.Count; i++)
            {
                PointVectorRelation tempRelation = ComputationalGeometry.GetPointVectorRelation(polygon.Vertexes[i], newVertexes[0], newVertexes[1]);

                if (tempRelation != relation)
                {
                    if (tempRelation == PointVectorRelation.LiesOnTheLine)
                    {
                        if (condition)
                        {
                            int temp = i - 1 >= 0 ? i - 1 : polygon.Vertexes.Count - 1;

                            result.Add(polygon.Neighbours[temp]);
                        }
                    }
                    else
                    {
                        condition = true;

                        int temp = i - 1 >= 0 ? i - 1 : polygon.Vertexes.Count - 1;

                        result.Add(polygon.Neighbours[temp]);
                    }
                }
            }

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