Ejemplo n.º 1
0
        public override bool IsIntersects(Node searchpoint, double quad)
        {
            // checking with border is the same as a polyline
            Node p1 = new Node(searchpoint.X - quad, searchpoint.Y + quad);
            Node p2 = new Node(searchpoint.X + quad, searchpoint.Y + quad);
            Node p3 = new Node(searchpoint.X + quad, searchpoint.Y - quad);
            Node p4 = new Node(searchpoint.X - quad, searchpoint.Y - quad);
            Node begin;
            Node end;

            for (int i = 0; i < NodeCount - 1; i++)
            {
                begin = _nodes[i];
                end   = _nodes[i + 1];

                if (Analysis.IsSegmentsIntersects(begin, end, p1, p2))
                {
                    return(true);
                }

                if (Analysis.IsSegmentsIntersects(begin, end, p2, p3))
                {
                    return(true);
                }

                if (Analysis.IsSegmentsIntersects(begin, end, p3, p4))
                {
                    return(true);
                }
                if (Analysis.IsSegmentsIntersects(begin, end, p4, p1))
                {
                    return(true);
                }
            }
            begin = _nodes[NodeCount - 1];
            end   = _nodes[0];
            //4 уравнения
            if (Analysis.IsSegmentsIntersects(begin, end, p1, p2))
            {
                return(true);
            }
            if (Analysis.IsSegmentsIntersects(begin, end, p2, p3))
            {
                return(true);
            }
            if (Analysis.IsSegmentsIntersects(begin, end, p3, p4))
            {
                return(true);
            }
            if (Analysis.IsSegmentsIntersects(begin, end, p4, p1))
            {
                return(true);
            }

            //Принадлежность в полигне

            return(Analysis.PointInsidePolygon(_nodes, searchpoint));
        }
Ejemplo n.º 2
0
        internal override bool IsIntersects(Node searchpoint, double quad)
        {
            //1. Проверка на пересечение с границей
            Node p1 = new Node(searchpoint.X - quad, searchpoint.Y + quad);
            Node p2 = new Node(searchpoint.X + quad, searchpoint.Y + quad);
            Node p3 = new Node(searchpoint.X + quad, searchpoint.Y - quad);
            Node p4 = new Node(searchpoint.X - quad, searchpoint.Y - quad);

            Node begin;
            Node end;

            for (int i = 0; i < NodeCount - 1; i++)
            {
                begin = _nodes[i];
                end   = _nodes[i + 1];
                if (Analysis.IsSegmentsIntersects(begin, end, p1, p2))
                {
                    return(true);
                }
                if (Analysis.IsSegmentsIntersects(begin, end, p2, p3))
                {
                    return(true);
                }
                if (Analysis.IsSegmentsIntersects(begin, end, p3, p4))
                {
                    return(true);
                }
                if (Analysis.IsSegmentsIntersects(begin, end, p4, p1))
                {
                    return(true);
                }
            }
            begin = _nodes[NodeCount - 1];
            end   = _nodes[0];
            if (Analysis.IsSegmentsIntersects(begin, end, p1, p2))
            {
                return(true);
            }
            if (Analysis.IsSegmentsIntersects(begin, end, p2, p3))
            {
                return(true);
            }
            if (Analysis.IsSegmentsIntersects(begin, end, p3, p4))
            {
                return(true);
            }
            if (Analysis.IsSegmentsIntersects(begin, end, p4, p1))
            {
                return(true);
            }
            //2. Принадлежность точки полигону
            return(Analysis.PointInsidePolygon(_nodes, searchpoint));
            //return false;
        }