Package org.locationtech.jts.algorithm
Class MinimumDiameter
- java.lang.Object
-
- org.locationtech.jts.algorithm.MinimumDiameter
-
public class MinimumDiameter extends java.lang.ObjectComputes the minimum diameter of aGeometry. The minimum diameter is defined to be the width of the smallest band that contains the geometry, where a band is a strip of the plane defined by two parallel lines. This can be thought of as the smallest hole that the geometry can be moved through, with a single rotation.The first step in the algorithm is computing the convex hull of the Geometry. If the input Geometry is known to be convex, a hint can be supplied to avoid this computation.
This class can also be used to compute a line segment representing the minimum diameter, the supporting line segment of the minimum diameter, and a minimum rectangle enclosing the input geometry. This rectangle will have width equal to the minimum diameter, and have one side parallel to the supporting segment.
- Version:
- 1.7
- See Also:
ConvexHull
-
-
Field Summary
Fields Modifier and Type Field Description private Coordinate[]convexHullPtsprivate GeometryinputGeomprivate booleanisConvexprivate LineSegmentminBaseSegprivate intminPtIndexprivate doubleminWidthprivate CoordinateminWidthPt
-
Constructor Summary
Constructors Constructor Description MinimumDiameter(Geometry inputGeom)Compute a minimum diameter for a givenGeometry.MinimumDiameter(Geometry inputGeom, boolean isConvex)Compute a minimum diameter for a giverGeometry, with a hint if the Geometry is convex (e.g.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static doublecomputeC(double a, double b, Coordinate p)private voidcomputeConvexRingMinDiameter(Coordinate[] pts)Compute the width information for a ring ofCoordinates.private voidcomputeMinimumDiameter()private static LineSegmentcomputeSegmentForLine(double a, double b, double c)private voidcomputeWidthConvex(Geometry convexGeom)private intfindMaxPerpDistance(Coordinate[] pts, LineSegment seg, int startIndex)LineStringgetDiameter()Gets aLineStringwhich is a minimum diameterdoublegetLength()Gets the length of the minimum diameter of the input Geometrystatic GeometrygetMinimumDiameter(Geometry geom)Gets the length of the minimum diameter enclosing a geometryGeometrygetMinimumRectangle()Gets the minimum rectangularPolygonwhich encloses the input geometry.static GeometrygetMinimumRectangle(Geometry geom)Gets the minimum rectangle enclosing a geometry.LineStringgetSupportingSegment()Gets the segment forming the base of the minimum diameterCoordinategetWidthCoordinate()Gets theCoordinateforming one end of the minimum diameterprivate static intnextIndex(Coordinate[] pts, int index)
-
-
-
Field Detail
-
inputGeom
private final Geometry inputGeom
-
isConvex
private final boolean isConvex
-
convexHullPts
private Coordinate[] convexHullPts
-
minBaseSeg
private LineSegment minBaseSeg
-
minWidthPt
private Coordinate minWidthPt
-
minPtIndex
private int minPtIndex
-
minWidth
private double minWidth
-
-
Constructor Detail
-
MinimumDiameter
public MinimumDiameter(Geometry inputGeom)
Compute a minimum diameter for a givenGeometry.- Parameters:
inputGeom- a Geometry
-
MinimumDiameter
public MinimumDiameter(Geometry inputGeom, boolean isConvex)
Compute a minimum diameter for a giverGeometry, with a hint if the Geometry is convex (e.g. a convex Polygon or LinearRing, or a two-point LineString, or a Point).- Parameters:
inputGeom- a Geometry which is convexisConvex-trueif the input geometry is convex
-
-
Method Detail
-
getMinimumRectangle
public static Geometry getMinimumRectangle(Geometry geom)
Gets the minimum rectangle enclosing a geometry.- Parameters:
geom- the geometry- Returns:
- the minimum rectangle enclosing the geometry
-
getMinimumDiameter
public static Geometry getMinimumDiameter(Geometry geom)
Gets the length of the minimum diameter enclosing a geometry- Parameters:
geom- the geometry- Returns:
- the length of the minimum diameter of the geometry
-
getLength
public double getLength()
Gets the length of the minimum diameter of the input Geometry- Returns:
- the length of the minimum diameter
-
getWidthCoordinate
public Coordinate getWidthCoordinate()
Gets theCoordinateforming one end of the minimum diameter- Returns:
- a coordinate forming one end of the minimum diameter
-
getSupportingSegment
public LineString getSupportingSegment()
Gets the segment forming the base of the minimum diameter- Returns:
- the segment forming the base of the minimum diameter
-
getDiameter
public LineString getDiameter()
Gets aLineStringwhich is a minimum diameter- Returns:
- a
LineStringwhich is a minimum diameter
-
computeMinimumDiameter
private void computeMinimumDiameter()
-
computeWidthConvex
private void computeWidthConvex(Geometry convexGeom)
-
computeConvexRingMinDiameter
private void computeConvexRingMinDiameter(Coordinate[] pts)
Compute the width information for a ring ofCoordinates. Leaves the width information in the instance variables.- Parameters:
pts-
-
findMaxPerpDistance
private int findMaxPerpDistance(Coordinate[] pts, LineSegment seg, int startIndex)
-
nextIndex
private static int nextIndex(Coordinate[] pts, int index)
-
getMinimumRectangle
public Geometry getMinimumRectangle()
Gets the minimum rectangularPolygonwhich encloses the input geometry. The rectangle has width equal to the minimum diameter, and a longer length. If the convex hull of the input is degenerate (a line or point) aLineStringorPointis returned.The minimum rectangle can be used as an extremely generalized representation for the given geometry.
- Returns:
- the minimum rectangle enclosing the input (or a line or point if degenerate)
-
computeC
private static double computeC(double a, double b, Coordinate p)
-
computeSegmentForLine
private static LineSegment computeSegmentForLine(double a, double b, double c)
-
-