private void ComputeMinDistancePolygonPoint(PlanarPolygon3D polyPlane, IPoint point, bool flip) { var pt = point.Coordinate; var shell = polyPlane.Polygon.ExteriorRing; if (polyPlane.Intersects(pt, shell)) { // point is either inside or in a hole int nHole = polyPlane.Polygon.NumInteriorRings; for (int i = 0; i < nHole; i++) { var hole = polyPlane.Polygon.GetInteriorRingN(i); if (polyPlane.Intersects(pt, hole)) { ComputeMinDistanceLinePoint(hole, point, flip); return; } } // point is in interior of polygon // distance is distance to polygon plane double dist = Math.Abs(polyPlane.Plane.OrientedDistance(pt)); UpdateDistance(dist, new GeometryLocation(polyPlane.Polygon, 0, pt), new GeometryLocation(point, 0, pt), flip ); } // point is outside polygon, so compute distance to shell linework ComputeMinDistanceLinePoint(shell, point, flip); }
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); double d0 = poly.Plane.OrientedDistance(p0); // for each segment in the line var p1 = new Coordinate(); for (int i = 0; i < seq.Count - 1; i++) { seq.GetCoordinate(i, p0); seq.GetCoordinate(i + 1, p1); double 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); }
private void ComputeMinDistancePolygonPoint(PlanarPolygon3D polyPlane, IPoint point, bool flip) { var pt = point.Coordinate; var shell = polyPlane.Polygon.ExteriorRing; if (polyPlane.Intersects(pt, shell)) { // point is either inside or in a hole var nHole = polyPlane.Polygon.NumInteriorRings; for (int i = 0; i < nHole; i++) { var hole = polyPlane.Polygon.GetInteriorRingN(i); if (polyPlane.Intersects(pt, hole)) { ComputeMinDistanceLinePoint(hole, point, flip); return; } } // point is in interior of polygon // distance is distance to polygon plane var dist = Math.Abs(polyPlane.Plane.OrientedDistance(pt)); UpdateDistance(dist, new GeometryLocation(polyPlane.Polygon, 0, pt), new GeometryLocation(point, 0, pt), flip ); } // point is outside polygon, so compute distance to shell linework ComputeMinDistanceLinePoint(shell, point, flip); }
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; }