JTS-Orientation方向计算

26 篇文章 3 订阅

org.locationtech.jts.algorithm.Orientation 使用说明

用于计算基本几何结构(包括点三重体(三角形)和环)的方向的函数。方向是平面几何的基本属性。

Orientation.index(Coordinate p1, Coordinate p2, Coordinate q)

说明

计算q点处在p1点->p2点方向的左侧还是右侧,左侧(逆时针方向)返回1,右侧(顺时针方向)返回-1

操作示例

在这里插入图片描述

package com.leokok.jts.learning.jts.core.algorithm;

import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.Coordinate;

/**
 * 用于计算基本几何结构(包括点三重体(三角形)和环)的方向的函数。方向是平面几何的基本属性。
 */
public class OrientationTest {

    public static void main(String[] args) {
        Coordinate p0 = new Coordinate(219.3649559090992, 140.84159161824724);
        Coordinate p1 = new Coordinate(168.9018919682399, -5.713787599646864);

        Coordinate p = new Coordinate(186.80814046338352, 46.28973405831556);
        int orient = Orientation.index(p0, p1, p);
        int orientInv = Orientation.index(p1, p0, p);

        System.out.println("p在p0->p1的左侧:"+orient);
        System.out.println("p在p1->p0的右侧:"+orientInv);
    }
}

输出:

p在p0->p1的左侧:-1
p在p1->p0的右侧:1

Orientation.isCCW(Coordinate[] ring)

说明

判断环是否是逆时针方向

操作示例

在这里插入图片描述

@Test
public void isCCWTest() throws ParseException {
    WKTReader wktReader = new WKTReader();
    Geometry geometry = wktReader.read("POLYGON ((415.1715 77.9175, 415.1712 77.9172, 415.1711 77.91685, 415.1717 77.9165, 415.1718 77.91649, 415.1724 77.9166, 415.1728 77.9169, 415.17286 77.91726, 415.1728 77.9176, 415.1725 77.9179, 415.1719 77.918, 415.1716 77.918, 415.1715 77.9175))");

    Coordinate[] coordinates = geometry.getCoordinates();

    System.out.println(Orientation.isCCW(coordinates));
}

输出 true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值