/** * Gets the extremal points which define the computed Minimum Bounding Circle. * There may be zero, one, two or three of these points, * depending on the number of points in the input * and the geometry of those points. * * @return the points defining the Minimum Bounding Circle */ public Coordinate[] getExtremalPoints() { compute(); return extremalPts; }
/** * Gets the centre point of the computed Minimum Bounding Circle. * * @return the centre point of the Minimum Bounding Circle * @return null if the input is empty */ public Coordinate getCentre() { compute(); return centre; }
/** * Gets the radius of the computed Minimum Bounding Circle. * * @return the radius of the Minimum Bounding Circle */ public double getRadius() { compute(); return radius; }
/** * Gets a geometry which represents the Minimum Bounding Circle. * If the input is degenerate (empty or a single unique point), * this method will return an empty geometry or a single Point geometry. * Otherwise, a Polygon will be returned which approximates the * Minimum Bounding Circle. * (Note that because the computed polygon is only an approximation, * it may not precisely contain all the input points.) * * @return a Geometry representing the Minimum Bounding Circle. */ public Geometry getCircle() { //TODO: ensure the output circle contains the extermal points. //TODO: or maybe even ensure that the returned geometry contains ALL the input points? compute(); if (centre == null) return input.getFactory().createPolygon(); Point centrePoint = input.getFactory().createPoint(centre); if (radius == 0.0) return centrePoint; return centrePoint.buffer(radius); }
/** * Gets a geometry representing a line between the two farthest points * in the input. * These points will be two of the extremal points of the Minimum Bounding Circle. * They also lie on the convex hull of the input. * * @return a LineString between the two farthest points of the input * @return a empty LineString if the input is empty * @return a Point if the input is a point */ public Geometry getFarthestPoints() { compute(); switch (extremalPts.length) { case 0: return input.getFactory().createLineString(); case 1: return input.getFactory().createPoint(centre); } Coordinate p0 = extremalPts[0]; Coordinate p1 = extremalPts[extremalPts.length - 1]; return input.getFactory().createLineString(new Coordinate[] { p0, p1 }); }
/** * Gets a geometry representing the diameter of the computed Minimum Bounding * Circle. * * @return the diameter LineString of the Minimum Bounding Circle * @return a empty LineString if the input is empty * @return a Point if the input is a point */ public Geometry getDiameter() { compute(); switch (extremalPts.length) { case 0: return input.getFactory().createLineString(); case 1: return input.getFactory().createPoint(centre); } // TODO: handle case of 3 extremal points, by computing a line from one of // them through the centre point with len = 2*radius Coordinate p0 = extremalPts[0]; Coordinate p1 = extremalPts[1]; return input.getFactory().createLineString(new Coordinate[] { p0, p1 }); }