高分悬赏:Java语言怎么获得一个多边形的最小外接圆的圆心坐标和半径呢
高分悬赏:Java语言怎么获得一个多边形的最小外接圆的圆心坐标和半径呢
有函数包:JTS Topology Suite
https://github.com/locationtech/jts
https://sourceforge.net/projects/jts-topo-suite/
这两者是新旧关系,接口名不同,但函数用法是一样的,
获得一个多边形的最小外接圆的圆心坐标和半径,调用其中的JTS's MinimumBoundingCircle 即可。
接口细节说明:https://docs.geotools.org/stable/userguide/library/jts/geometry.html
多边形的初始化 方法1:
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords =
new Coordinate[] {new Coordinate(4, 0), new Coordinate(2, 2),
new Coordinate(4, 4), new Coordinate(6, 2), new Coordinate(4, 0) };
LinearRing ring = geometryFactory.createLinearRing( coords );
LinearRing holes[] = null; // use LinearRing[] to represent holes
Polygon polygon = geometryFactory.createPolygon(ring, holes );
多边形的初始化 方法2 WKT:
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
WKTReader reader = new WKTReader( geometryFactory );
String wtkdata = "POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))";
Polygon polygon = (Polygon) reader.read(wtkdata);
调用其中的JTS's MinimumBoundingCircle
MinimumBoundingCircle circle = new MinimumBoundingCircle( polygon);
Coordinate co=circle.getCentre();
double ra = circle.getRadius();