JTS: 24 MinimumDiameter 最小矩形

文章目录

      • 版本
      • 代码

版本

org.locationtech.jts:jts-core:1.19.0
链接: github

代码

JTS: 24 MinimumDiameter 最小矩形_第1张图片
JTS: 24 MinimumDiameter 最小矩形_第2张图片
JTS: 24 MinimumDiameter 最小矩形_第3张图片

package pers.stu.algorithm;

import org.locationtech.jts.algorithm.MinimumDiameter;
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-15 14:11:53
 */
public class MinimumDiameterUse {

    private static final Logger LOGGER = LoggerFactory.getLogger(MinimumDiameterUse.class);

    public static void main(String[] args) {
        MinimumDiameterUse minimumDiameterUse = new MinimumDiameterUse();
        minimumDiameterUse.test00();
    }

    public void test00() {
        GeometryFactory geometryFactory = new GeometryFactory();
        Coordinate[] coordinates = new Coordinate[] {
                new Coordinate(7, 11), new Coordinate(6, 7), new Coordinate(9, 5), new Coordinate(13.1, 5),
                new Coordinate(16, 8), new Coordinate(18, 10), new Coordinate(19, 11), new Coordinate(7, 11)
        };

        Polygon polygon = geometryFactory.createPolygon(coordinates);

        // 获取最小矩形
        Geometry geometry1 = MinimumDiameter.getMinimumRectangle(polygon);
        LOGGER.info("geometry1: {}", geometry1);

        LOGGER.info(GeoGebraUtil.compare(geometry1));

        // 获取最小直径
        Geometry geometry2 = MinimumDiameter.getMinimumDiameter(polygon);
        LOGGER.info("geometry2: {}", geometry2);

        LOGGER.info(GeoGebraUtil.compare(geometry2));
    }
}

你可能感兴趣的:(JTS,JTS)