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);
            }
        }
Exemple #2
0
        private void DivideTheRegionWithPointInTheRegion(VoronoiCell polygon, Point point)
        {
            Point midPoint = ComputationalGeometry.CalculateMidPoint(point, polygon.PrimaryPoint);

            Point temPoint = new Point(midPoint.X + 10, midPoint.Y - 10 / ComputationalGeometry.CalculateSlope(point, polygon.PrimaryPoint));

            List <int> edgeIndexes;

            List <Point> newVertexes = polygon.Intersect(midPoint, temPoint, out edgeIndexes);

            //20/12/2009
            if (newVertexes.Count != 2)
            {
                throw new NotImplementedException();
            }

            List <int> affectedPolygons = GetAffectedPolygons(polygon, newVertexes, edgeIndexes);

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

            for (int i = 0; i < affectedPolygons.Count; i++)
            {
                if (affectedPolygons[i] == -1)
                {
                    continue;
                }

                List <Point> p2 = MakeUpPolygon(affectedPolygons[i], point);

                foreach (Point item in p2)
                {
                    if (!this.vertexes.Contains(item))
                    {
                        this.vertexes.Add(item);
                    }
                    if (!ii.Contains(item.GetHashCode()))
                    {
                        ii.Add(item.GetHashCode());
                    }
                }
            }

            this.polygons.Add(new QuasiVoronoiCell(point, ii));
            //20/12/2009

            //check if neighbour exists!
            //newVertexes is for check!
            //int nextPolygon = MakeUpPolygon(polygon.Neighbours[edgeIndexes[0]], newVertexes[0], point);
        }
        private double CalculatePerimeter()
        {
            double tempValue = 0;

            int count = this.Count;

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

                tempValue += ComputationalGeometry.CalculateDistance(Vertexes[i], Vertexes[j]);
            }

            return(tempValue);
        }
Exemple #4
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 List <Point> Intersect(Point firstPointLine, Point secondPointLine, out List <int> edgeIndexes)
        {
            List <Point> result = new List <Point>();

            edgeIndexes = new List <int>();

            int count = this.Vertexes.Count;

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

                Point intersection;

                LineLineSegmentRelation relation = ComputationalGeometry.IntersectLineWithLineSegment(firstPointLine, secondPointLine, Vertexes[i], Vertexes[j], out intersection);

                if (relation == LineLineSegmentRelation.Intersect)
                {
                    //check if intersection is not the vertex!
                    if (!result.Contains(intersection) && !intersection.AreTheSame(Vertexes[i], 10))
                    {
                        result.Add(intersection);

                        edgeIndexes.Add(i);
                    }
                }
                else if (relation == LineLineSegmentRelation.Coinciding)
                {
                    if (!result.Contains(Vertexes[j]))
                    {
                        result.Add(Vertexes[j]);

                        edgeIndexes.Add(i);
                    }
                }
            }

            return(result);
        }
Exemple #6
0
        private List <Point> MakeUpPolygon(int polygonCode, Point point)
        {
            VoronoiCell polygon = this.GetPolygon(polygonCode);

            Point midPoint = ComputationalGeometry.CalculateMidPoint(point, polygon.PrimaryPoint);

            Point temPoint = new Point(midPoint.X + 10, midPoint.Y - 10 / ComputationalGeometry.CalculateSlope(point, polygon.PrimaryPoint));

            List <int> edgeIndexes;

            List <Point> newVertexes = polygon.Intersect(midPoint, temPoint, out edgeIndexes);

            if (newVertexes.Count == 1)
            {
                return(newVertexes);
            }

            if (newVertexes.Count != 2)
            {
                throw new NotImplementedException();
            }

            VoronoiCell first = new VoronoiCell(polygon.PrimaryPoint);

            first.Vertexes.Add(newVertexes[1]);

            first.Vertexes.Add(newVertexes[0]);

            for (int i = edgeIndexes[0] + 1; i < edgeIndexes[1]; i++)
            {
                first.Vertexes.Add(polygon.Vertexes[i]);

                first.Neighbours.Add(polygon.Neighbours[i - 1]);
            }

            VoronoiCell second = new VoronoiCell(polygon.PrimaryPoint);

            for (int i = edgeIndexes[1] + 1; i < polygon.Vertexes.Count; i++)
            {
                second.Vertexes.Add(polygon.Vertexes[i]);

                first.Neighbours.Add(polygon.Neighbours[i]);
            }

            for (int i = 0; i < edgeIndexes[0]; i++)
            {
                second.Vertexes.Add(polygon.Vertexes[i]);

                first.Neighbours.Add(polygon.Neighbours[i]);
            }

            second.Vertexes.Add(newVertexes[0]);

            second.Vertexes.Add(newVertexes[1]);

            if (first.GetRelationTo(polygon.PrimaryPoint) == PointPolygonRelation.In)
            {
                polygon = first;
            }
            else
            {
                polygon = second;
            }

            return(newVertexes);
        }