Ejemplo n.º 1
0
        private static Coordinate Intersection(PlanarPolygon3D poly, ILineString line)
        {
            var seq = line.CoordinateSequence;

            if (seq.Count == 0)
            {
                return(null);
            }

            // start point of line
            var p0 = new Coordinate();

            seq.GetCoordinate(0, p0);
            var d0 = poly.Plane.OrientedDistance(p0);

            // for each segment in the line
            var p1 = new Coordinate();

            for (var i = 0; i < seq.Count - 1; i++)
            {
                seq.GetCoordinate(i, p0);
                seq.GetCoordinate(i + 1, p1);
                var d1 = poly.Plane.OrientedDistance(p1);

                /**
                 * If the oriented distances of the segment endpoints have the same sign,
                 * the segment does not cross the plane, and is skipped.
                 */
                if (d0 * d1 > 0)
                {
                    continue;
                }

                /**
                 * Compute segment-plane intersection point
                 * which is then used for a point-in-polygon test.
                 * The endpoint distances to the plane d0 and d1
                 * give the proportional distance of the intersection point
                 * along the segment.
                 */
                var intPt = SegmentPoint(p0, p1, d0, d1);
                // Coordinate intPt = polyPlane.intersection(p0, p1, s0, s1);
                if (poly.Intersects(intPt))
                {
                    return(intPt);
                }

                // shift to next segment
                d0 = d1;
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>Compute distance between a polygon and the rings of another.</summary>
        private void ComputeMinDistancePolygonRings(PlanarPolygon3D poly, IPolygon ringPoly,
                                                    bool flip)
        {
            // compute shell ring
            ComputeMinDistancePolygonLine(poly, ringPoly.ExteriorRing, flip);
            if (_isDone)
            {
                return;
            }
            // compute hole rings
            int nHole = ringPoly.NumInteriorRings;

            for (int i = 0; i < nHole; i++)
            {
                ComputeMinDistancePolygonLine(poly, ringPoly.GetInteriorRingN(i), flip);
                if (_isDone)
                {
                    return;
                }
            }
        }