文章目录
- 版本
- 代码
版本
org.locationtech.jts:jts-core:1.19.0
链接: github
代码
package pers.stu.algorithm;
import org.locationtech.jts.algorithm.MinimumBoundingCircle;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Polygon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pers.stu.util.GeoGebraUtil;
/**
* 最小包裹圆
* @author LiHan
* 2023-11-13 17:11:13
*/
public class MinimumBoundingCircleUse {
private static final Logger LOGGER = LoggerFactory.getLogger(MinimumBoundingCircleUse.class);
public static void main(String[] args) {
MinimumBoundingCircleUse minimumBoundingCircleUse = new MinimumBoundingCircleUse();
minimumBoundingCircleUse.test00();
}
public void test00() {
Coordinate[] coordinates = new Coordinate[] {
new Coordinate(4, 14), new Coordinate(13,14), new Coordinate(13,8), new Coordinate(4,8),
new Coordinate(4, 14)
};
GeometryFactory geometryFactory = new GeometryFactory();
Polygon polygon = geometryFactory.createPolygon(coordinates);
MinimumBoundingCircle minimumBoundingCircle = new MinimumBoundingCircle(polygon);
// 最小图形的直径
Geometry geometry1 = minimumBoundingCircle.getDiameter();
// 最小边界圆
Geometry geometry2 = minimumBoundingCircle.getCircle();
// 圆的直径
Geometry geometry3 = minimumBoundingCircle.getMaximumDiameter();
LOGGER.info("原始数据:{}, getDiameter数据:{}", geometry1, GeoGebraUtil.compare(geometry1));
LOGGER.info("原始数据:{}, getCircle数据:{}", geometry2, GeoGebraUtil.compare(geometry2));
LOGGER.info("原始数据:{}, getMaximumDiameter数据:{}", geometry3, GeoGebraUtil.compare(geometry3));
}
}
18:22:42.657 [main] INFO pers.stu.util.GeoGebraUtil - geometry类型:LineString
18:22:42.666 [main] INFO pers.stu.algorithm.MinimumBoundingCircleUse - 原始数据:LINESTRING (4 8, 13 8), getDiameter数据:Polyline(Point({4.0,8.0}),Point({13.0,8.0}))
18:22:42.666 [main] INFO pers.stu.util.GeoGebraUtil - geometry类型:Polygon
18:22:42.667 [main] INFO pers.stu.algorithm.MinimumBoundingCircleUse - 原始数据:POLYGON ((13.908326913195985 11, 13.804407428071261 9.944887760936103, 13.496642540231717 8.93032289350567, 12.996859481720486 7.995294556589521, 12.32426463519459 7.175735364805412, 11.50470544341048 6.503140518279514, 10.56967710649433 6.003357459768283, 9.555112239063899 5.695592571928739, 8.5 5.591673086804016, 7.444887760936103 5.695592571928739, 6.43032289350567 6.003357459768283, 5.495294556589522 6.503140518279513, 4.675735364805412 7.17573536480541, 4.003140518279513 7.995294556589521, 3.5033574597682833 8.93032289350567, 3.1955925719287386 9.944887760936101, 3.0916730868040156 11, 3.1955925719287386 12.055112239063899, 3.5033574597682833 13.06967710649433, 4.003140518279513 14.004705443410478, 4.67573536480541 14.824264635194588, 5.495294556589521 15.496859481720486, 6.430322893505666 15.996642540231715, 7.4448877609361 16.30440742807126, 8.499999999999998 16.408326913195985, 9.555112239063899 16.30440742807126, 10.569677106494332 15.996642540231715, 11.504705443410478 15.496859481720488, 12.324264635194588 14.82426463519459, 12.996859481720486 14.00470544341048, 13.496642540231715 13.069677106494334, 13.804407428071261 12.0551122390639, 13.908326913195985 11)), getCircle数据:Polygon(Point({13.908326913195985,11.0}),Point({13.804407428071261,9.944887760936103}),Point({13.496642540231717,8.93032289350567}),Point({12.996859481720486,7.995294556589521}),Point({12.32426463519459,7.175735364805412}),Point({11.50470544341048,6.503140518279514}),Point({10.56967710649433,6.003357459768283}),Point({9.555112239063899,5.695592571928739}),Point({8.5,5.591673086804016}),Point({7.444887760936103,5.695592571928739}),Point({6.43032289350567,6.003357459768283}),Point({5.495294556589522,6.503140518279513}),Point({4.675735364805412,7.17573536480541}),Point({4.003140518279513,7.995294556589521}),Point({3.5033574597682833,8.93032289350567}),Point({3.1955925719287386,9.944887760936101}),Point({3.0916730868040156,11.0}),Point({3.1955925719287386,12.055112239063899}),Point({3.5033574597682833,13.06967710649433}),Point({4.003140518279513,14.004705443410478}),Point({4.67573536480541,14.824264635194588}),Point({5.495294556589521,15.496859481720486}),Point({6.430322893505666,15.996642540231715}),Point({7.4448877609361,16.30440742807126}),Point({8.499999999999998,16.408326913195985}),Point({9.555112239063899,16.30440742807126}),Point({10.569677106494332,15.996642540231715}),Point({11.504705443410478,15.496859481720488}),Point({12.324264635194588,14.82426463519459}),Point({12.996859481720486,14.00470544341048}),Point({13.496642540231715,13.069677106494334}),Point({13.804407428071261,12.0551122390639}),Point({13.908326913195985,11.0}))
18:22:42.668 [main] INFO pers.stu.util.GeoGebraUtil - geometry类型:LineString
18:22:42.668 [main] INFO pers.stu.algorithm.MinimumBoundingCircleUse - 原始数据:LINESTRING (13 8, 4 14), getMaximumDiameter数据:Polyline(Point({13.0,8.0}),Point({4.0,14.0}))