computeMinimumDiameter(); double paraC = computeC(dx, dy, convexHullPts[i]); if (paraC > maxPara) maxPara = paraC; if (paraC < minPara) minPara = paraC; double perpC = computeC(-dy, dx, convexHullPts[i]); if (perpC > maxPerp) maxPerp = perpC; if (perpC < minPerp) minPerp = perpC; LineSegment maxPerpLine = computeSegmentForLine(-dx, -dy, maxPerp); LineSegment minPerpLine = computeSegmentForLine(-dx, -dy, minPerp); LineSegment maxParaLine = computeSegmentForLine(-dy, dx, maxPara); LineSegment minParaLine = computeSegmentForLine(-dy, dx, minPara);
private void computeMinimumDiameter() { // check if computation is cached if (minWidthPt != null) return; if (isConvex) computeWidthConvex(inputGeom); else { Geometry convexGeom = (new ConvexHull(inputGeom)).getConvexHull(); computeWidthConvex(convexGeom); } }
/** * Compute the width information for a ring of {@link Coordinate}s. * Leaves the width information in the instance variables. * * @param pts */ private void computeConvexRingMinDiameter(Coordinate[] pts) { // for each segment in the ring minWidth = Double.MAX_VALUE; int currMaxIndex = 1; LineSegment seg = new LineSegment(); // compute the max distance for all segments in the ring, and pick the minimum for (int i = 0; i < pts.length - 1; i++) { seg.p0 = pts[i]; seg.p1 = pts[i + 1]; currMaxIndex = findMaxPerpDistance(pts, seg, currMaxIndex); } }
static public Geometry minimumRectangle(Geometry g) { if (g == null) return null; MinimumDiameter min = new MinimumDiameter(g); return min.getMinimumRectangle(); }
public static LineString minimumDiameter(Geometry geometry){ if(geometry == null){ return null; } return new MinimumDiameter(geometry).getDiameter(); } }
/** * Gets the length of the minimum diameter of the input Geometry * * @return the length of the minimum diameter */ public double getLength() { computeMinimumDiameter(); return minWidth; }
private int findMaxPerpDistance(Coordinate[] pts, LineSegment seg, int startIndex) { double maxPerpDistance = seg.distancePerpendicular(pts[startIndex]); double nextPerpDistance = maxPerpDistance; int maxIndex = startIndex; int nextIndex = maxIndex; while (nextPerpDistance >= maxPerpDistance) { maxPerpDistance = nextPerpDistance; maxIndex = nextIndex; nextIndex = nextIndex(pts, maxIndex); nextPerpDistance = seg.distancePerpendicular(pts[nextIndex]); } // found maximum width for this segment - update global min dist if appropriate if (maxPerpDistance < minWidth) { minPtIndex = maxIndex; minWidth = maxPerpDistance; minWidthPt = pts[minPtIndex]; minBaseSeg = new LineSegment(seg); // System.out.println(minBaseSeg); // System.out.println(minWidth); } return maxIndex; }
private void computeWidthConvex(Geometry convexGeom) { //System.out.println("Input = " + geom); if (convexGeom instanceof Polygon) convexHullPts = ((Polygon) convexGeom).getExteriorRing().getCoordinates(); else convexHullPts = convexGeom.getCoordinates(); // special cases for lines or points or degenerate rings if (convexHullPts.length == 0) { minWidth = 0.0; minWidthPt = null; minBaseSeg = null; } else if (convexHullPts.length == 1) { minWidth = 0.0; minWidthPt = convexHullPts[0]; minBaseSeg.p0 = convexHullPts[0]; minBaseSeg.p1 = convexHullPts[0]; } else if (convexHullPts.length == 2 || convexHullPts.length == 3) { minWidth = 0.0; minWidthPt = convexHullPts[0]; minBaseSeg.p0 = convexHullPts[0]; minBaseSeg.p1 = convexHullPts[1]; } else computeConvexRingMinDiameter(convexHullPts); }
/** * Gets the minimum rectangle enclosing a geometry. * * @param geom the geometry * @return the minimum rectangle enclosing the geometry */ public static Geometry getMinimumRectangle(Geometry geom) { return (new MinimumDiameter(geom)).getMinimumRectangle(); }
static public Geometry minimumDiameter(Geometry arg0) { if (arg0 == null) return null; MinimumDiameter minDiameter = new MinimumDiameter(arg0); return minDiameter.getDiameter(); }
/** * Gets the {@link Coordinate} forming one end of the minimum diameter * * @return a coordinate forming one end of the minimum diameter */ public Coordinate getWidthCoordinate() { computeMinimumDiameter(); return minWidthPt; }
private int findMaxPerpDistance(Coordinate[] pts, LineSegment seg, int startIndex) { double maxPerpDistance = seg.distancePerpendicular(pts[startIndex]); double nextPerpDistance = maxPerpDistance; int maxIndex = startIndex; int nextIndex = maxIndex; while (nextPerpDistance >= maxPerpDistance) { maxPerpDistance = nextPerpDistance; maxIndex = nextIndex; nextIndex = nextIndex(pts, maxIndex); nextPerpDistance = seg.distancePerpendicular(pts[nextIndex]); } // found maximum width for this segment - update global min dist if appropriate if (maxPerpDistance < minWidth) { minPtIndex = maxIndex; minWidth = maxPerpDistance; minWidthPt = pts[minPtIndex]; minBaseSeg = new LineSegment(seg); // System.out.println(minBaseSeg); // System.out.println(minWidth); } return maxIndex; }
private void computeWidthConvex(Geometry convexGeom) { //System.out.println("Input = " + geom); if (convexGeom instanceof Polygon) convexHullPts = ((Polygon) convexGeom).getExteriorRing().getCoordinates(); else convexHullPts = convexGeom.getCoordinates(); // special cases for lines or points or degenerate rings if (convexHullPts.length == 0) { minWidth = 0.0; minWidthPt = null; minBaseSeg = null; } else if (convexHullPts.length == 1) { minWidth = 0.0; minWidthPt = convexHullPts[0]; minBaseSeg.p0 = convexHullPts[0]; minBaseSeg.p1 = convexHullPts[0]; } else if (convexHullPts.length == 2 || convexHullPts.length == 3) { minWidth = 0.0; minWidthPt = convexHullPts[0]; minBaseSeg.p0 = convexHullPts[0]; minBaseSeg.p1 = convexHullPts[1]; } else computeConvexRingMinDiameter(convexHullPts); }
/** * Gets the minimum rectangular {@link Polygon} which encloses the input geometry. * @param geometry Input geometry * @return */ public static Geometry computeMinimumRectangle(Geometry geometry){ if(geometry == null){ return null; } return new MinimumDiameter(geometry).getMinimumRectangle(); } }
/** * Gets the length of the minimum diameter enclosing a geometry * @param geom the geometry * @return the length of the minimum diameter of the geometry */ public static Geometry getMinimumDiameter(Geometry geom) { return (new MinimumDiameter(geom)).getDiameter(); }
computeMinimumDiameter(); double paraC = computeC(dx, dy, convexHullPts[i]); if (paraC > maxPara) maxPara = paraC; if (paraC < minPara) minPara = paraC; double perpC = computeC(-dy, dx, convexHullPts[i]); if (perpC > maxPerp) maxPerp = perpC; if (perpC < minPerp) minPerp = perpC; LineSegment maxPerpLine = computeSegmentForLine(-dx, -dy, maxPerp); LineSegment minPerpLine = computeSegmentForLine(-dx, -dy, minPerp); LineSegment maxParaLine = computeSegmentForLine(-dy, dx, maxPara); LineSegment minParaLine = computeSegmentForLine(-dy, dx, minPara);
/** * Gets the segment forming the base of the minimum diameter * * @return the segment forming the base of the minimum diameter */ public LineString getSupportingSegment() { computeMinimumDiameter(); return inputGeom.getFactory().createLineString(new Coordinate[] { minBaseSeg.p0, minBaseSeg.p1 } ); }
private void computeMinimumDiameter() { // check if computation is cached if (minWidthPt != null) return; if (isConvex) computeWidthConvex(inputGeom); else { Geometry convexGeom = (new ConvexHull(inputGeom)).getConvexHull(); computeWidthConvex(convexGeom); } }
/** * Compute the width information for a ring of {@link Coordinate}s. * Leaves the width information in the instance variables. * * @param pts */ private void computeConvexRingMinDiameter(Coordinate[] pts) { // for each segment in the ring minWidth = Double.MAX_VALUE; int currMaxIndex = 1; LineSegment seg = new LineSegment(); // compute the max distance for all segments in the ring, and pick the minimum for (int i = 0; i < pts.length - 1; i++) { seg.p0 = pts[i]; seg.p1 = pts[i + 1]; currMaxIndex = findMaxPerpDistance(pts, seg, currMaxIndex); } }
/** * Gets the minimum rectangular {@link Polygon} which encloses the input geometry. * @param geometry Input geometry * @return */ public static Geometry computeMinimumRectangle(Geometry geometry){ if(geometry == null){ return null; } return new MinimumDiameter(geometry).getMinimumRectangle(); } }