Example #1
0
        }         // public override bool IsCCW(Coordinates ring)

        /// <summary>
        ///		This algorithm does not attempt to first check the point against the envelope
        ///		of the ring.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="ring">Assumed to have first point identical to last point</param>
        /// <returns></returns>
        public override bool IsPointInRing(Coordinate p, Coordinates ring)
        {
            int    i;
            int    i1;                // point index; i1 = i-1
            double xInt;              // x intersection of segment with ray
            int    crossings = 0;     // number of segment/ray crossings
            double x1;                // translated coordinates
            double y1;
            double x2;
            double y2;
            int    nPts = ring.Count;

            //
            //  For each segment l = (i-1, i), see if it crosses ray from test point in positive x direction.
            //
            for (i = 1; i < nPts; i++)
            {
                i1 = i - 1;
                Coordinate p1 = ring[i];
                Coordinate p2 = ring[i1];
                x1 = p1.X - p.X;
                y1 = p1.Y - p.Y;
                x2 = p2.X - p.X;
                y2 = p2.Y - p.Y;

                if (((y1 > 0) && (y2 <= 0)) ||
                    ((y2 > 0) && (y1 <= 0)))
                {
                    //
                    //  segment straddles x axis, so compute intersection.
                    //
                    xInt = RobustDeterminant.SignOfDet2x2(x1, y1, x2, y2) / (y2 - y1);
                    //xsave = xInt;
                    //
                    //  crosses ray if strictly positive intersection.
                    //
                    if (0.0 < xInt)
                    {
                        crossings++;
                    }
                }
            }
            //
            //  p is inside if number of crossings is odd.
            //
            if ((crossings % 2) == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }         // public override bool IsPointInPolygon(Coordinate p, Coordinates ring)
Example #2
0
        public static int OrientationIndex(Coordinate p1, Coordinate p2, Coordinate q)
        {
            // travelling along p1->p2, turn counter clockwise to get to q return 1,
            // travelling along p1->p2, turn clockwise to get to q return -1,
            // p1, p2 and q are colinear return 0.
            double dx1 = p2.X - p1.X;
            double dy1 = p2.Y - p1.Y;
            double dx2 = q.X - p2.X;
            double dy2 = q.Y - p2.Y;

            return(RobustDeterminant.SignOfDet2x2(dx1, dy1, dx2, dy2));
        }         // public static int OrientationIndex(Coordinate p1, Coordinate p2, Coordinate q)
Example #3
0
        private void TestLineSegment(Coordinate p, LineSegment seg)
        {
            double xInt;              // x intersection of segment with ray
            double x1;                // translated coordinates
            double y1;
            double x2;
            double y2;

            //
            //  Test if segment crosses ray from test point in positive x direction.
            //
            Coordinate p1 = seg.P0;
            Coordinate p2 = seg.P1;

            x1 = p1.X - p.X;
            y1 = p1.Y - p.Y;
            x2 = p2.X - p.X;
            y2 = p2.Y - p.Y;

            if (((y1 > 0) && (y2 <= 0)) ||
                ((y2 > 0) && (y1 <= 0)))
            {
                //
                //  segment straddles x axis, so compute intersection.
                //
                xInt = RobustDeterminant.SignOfDet2x2(x1, y1, x2, y2) / (y2 - y1);
                //xsave = xInt;
                //
                //  crosses ray if strictly positive intersection.
                //
                if (0.0 < xInt)
                {
                    _crossings++;
                }
            }
        }