Exemple #1
0
 /// <summary>
 /// Computes the intersion of point p and line p1-p2.
 /// </summary>
 /// <param name="p">Coordinate of point p.</param>
 /// <param name="p1">Coordinate of line p1-p2.</param>
 /// <param name="p2">Coordinate of line p1-p2.</param>
 public override void ComputeIntersection(Coordinate p, Coordinate p1, Coordinate p2)
 {
     _isProper = false;
     if ((RobustCGAlgorithms.OrientationIndex(p1, p2, p) == 0) &&
         (RobustCGAlgorithms.OrientationIndex(p2, p1, p) == 0))
     {
         if (Between(p1, p2, p))
         {
             _isProper = true;
             if (p.Equals(p1) || p.Equals(p2))
             {
                 _isProper = false;
             }
             _result = DO_INTERSECT;
             return;
         }
         else
         {
             _result = DONT_INTERSECT;
             return;
         }
     }
     else
     {
         _result = DONT_INTERSECT;
     }
 }         // public override void ComputeIntersection(Coordinate p, Coordinate p1, Coordinate p2)
Exemple #2
0
        }         // public override void ComputeIntersection(Coordinate p, Coordinate p1, Coordinate p2)

        /// <summary>
        /// Computes the intersection of line p1-p2 and line q1-q2.
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="q1"></param>
        /// <param name="q2"></param>
        /// <returns></returns>
        protected override int ComputeIntersect(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2)
        {
            _isProper = false;
            // for each endpoint, compute which side of the other segment it lies
            int Pq1 = RobustCGAlgorithms.OrientationIndex(p1, p2, q1);
            int Pq2 = RobustCGAlgorithms.OrientationIndex(p1, p2, q2);
            int Qp1 = RobustCGAlgorithms.OrientationIndex(q1, q2, p1);
            int Qp2 = RobustCGAlgorithms.OrientationIndex(q1, q2, p2);

            // if both endpoints lie on the same side of the other segment, the segments do not intersect
            if (Pq1 > 0 && Pq2 > 0)
            {
                return(DONT_INTERSECT);
            }
            if (Qp1 > 0 && Qp2 > 0)
            {
                return(DONT_INTERSECT);
            }
            if (Pq1 < 0 && Pq2 < 0)
            {
                return(DONT_INTERSECT);
            }
            if (Qp1 < 0 && Qp2 < 0)
            {
                return(DONT_INTERSECT);
            }
            bool isCollinear = ((Pq1 == 0) && (Pq2 == 0) && (Qp1 == 0) && (Qp2 == 0));

            if (isCollinear)
            {
                return(ComputeCollinearIntersection(p1, p2, q1, q2));
            }
            //
            //  Check if the intersection is an endpoint. If it is, copy the endpoint as
            //  the intersection point. Copying the point rather than computing it
            //  ensures the point has the exact value, which is important for
            //  robustness. It is sufficient to simply check for an endpoint which is on
            //  the other line, since at this point we know that the inputLines must
            //  intersect.
            //
            if (Pq1 == 0 || Pq2 == 0 || Qp1 == 0 || Qp2 == 0)
            {
                _isProper = false;
                if (Pq1 == 0)
                {
                    _intPt[0] = new Coordinate(q1);
                }
                if (Pq2 == 0)
                {
                    _intPt[0] = new Coordinate(q2);
                }
                if (Qp1 == 0)
                {
                    _intPt[0] = new Coordinate(p1);
                }
                if (Qp2 == 0)
                {
                    _intPt[0] = new Coordinate(p2);
                }
            }
            else
            {
                _isProper = true;
                _intPt[0] = Intersection(p1, p2, q1, q2);
            }
            return(DO_INTERSECT);
        }         // protected override int ComputeIntersect(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2)