这里写目录标题
- 版本
- 代码
版本
org.locationtech.jts:jts-core:1.19.0
链接: github
代码
package pers.stu.algorithm;
import org.locationtech.jts.algorithm.Angle;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 角度使用
* @author LiHan
* 2023-11-06 10:11:54
*/
public class AngleUse {
private static final Logger LOGGER = LoggerFactory.getLogger(AngleUse.class);
private Coordinate A = null;
private Coordinate B = null;
private Coordinate C = null;
public static void main(String[] args) {
AngleUse angleUse = new AngleUse();
angleUse.init();
angleUse.test02();
}
public void init() {
A = new Coordinate(1, 3);
B = new Coordinate(1, 1);
C = new Coordinate(3, 1);
}
public void test00() {
LOGGER.info("是否是锐角:{}", Angle.isAcute(A, B, C));
LOGGER.info("是否是钝角:{}", Angle.isObtuse(A, B, C));
LOGGER.info("最小夹角:{}", Angle.angleBetween(A, B, C));
LOGGER.info("最小夹角:{}", Angle.toDegrees(Angle.angleBetween(A, B, C)));
/*
17:11:40.006 [main] INFO pers.stu.algorithm.AngleUse - 是否是锐角:false
17:11:40.007 [main] INFO pers.stu.algorithm.AngleUse - 是否是钝角:false
17:11:40.008 [main] INFO pers.stu.algorithm.AngleUse - 最小夹角:1.5707963267948966
17:11:40.008 [main] INFO pers.stu.algorithm.AngleUse - 最小夹角:90.0
*/
}
public void test01() {
//找对应的位置 0到180(逆时针)之间返回正数,180-360(顺时针)之前返回负数
System.out.println(Angle.toDegrees(Angle.normalize(Angle.toRadians(50))));
//50.0
System.out.println(Angle.toDegrees(Angle.normalize(Angle.toRadians(181))));
//-179.0
System.out.println(Angle.toDegrees(Angle.normalize(Angle.toRadians(369))));
//9.0
System.out.println(Angle.toDegrees(Angle.normalize(Angle.toRadians(-10))));
//-10.0
}
public void test02() {
Coordinate Bi = new Coordinate(0,2);
Coordinate Ai = new Coordinate(1,1);
Coordinate Ci = new Coordinate(1,3);
//延Ai-Bi边逆时针转到Ai-CI边的角度值
System.out.println("Angle.interiorAngle(Bi,Ai,Ci)角度="+Angle.toDegrees(Angle.interiorAngle(Bi,Ai,Ci)));
//Angle.interiorAngle(Bi,Ai,Ci)角度=315.0
//延Ci-Ai边逆时针转到Ai-BI边的角度值
System.out.println("Angle.interiorAngle(Ci,Ai,Bi)角度="+Angle.toDegrees(Angle.interiorAngle(Ci,Ai,Bi)));
//Angle.interiorAngle(Ci,Ai,Bi)角度=45.0
}
}