public PlanarPolygon3D(Polygon poly) { this.poly = poly; plane = findBestFitPlane(poly); facingPlane = plane.closestAxisPlane(); }
double d0 = poly.getPlane().orientedDistance(p0); seq.getCoordinate(i, p0); seq.getCoordinate(i + 1, p1); double d1 = poly.getPlane().orientedDistance(p1);
/** * Finds a best-fit plane for the polygon, * by sampling a few points from the exterior ring. * <p> * The algorithm used is Newell's algorithm: * - a base point for the plane is determined from the average of all vertices * - the normal vector is determined by * computing the area of the projections on each of the axis planes * * @param poly the polygon to determine the plane for * @return the best-fit plane */ private Plane3D findBestFitPlane(Polygon poly) { CoordinateSequence seq = poly.getExteriorRing().getCoordinateSequence(); Coordinate basePt = averagePoint(seq); Vector3D normal = averageNormal(seq); return new Plane3D(normal, basePt); }
private void computeMinDistancePolygonPoint(PlanarPolygon3D polyPlane, Point point, boolean flip) { Coordinate pt = point.getCoordinate(); LineString shell = polyPlane.getPolygon().getExteriorRing(); if (polyPlane.intersects(pt, shell)) { // point is either inside or in a hole int nHole = polyPlane.getPolygon().getNumInteriorRing(); for (int i = 0; i < nHole; i++) { LineString hole = polyPlane.getPolygon().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.getPlane().orientedDistance(pt)); updateDistance(dist, new GeometryLocation(polyPlane.getPolygon(), 0, pt), new GeometryLocation(point, 0, pt), flip ); } // point is outside polygon, so compute distance to shell linework computeMinDistanceLinePoint(shell, point, flip); }