有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java检查路线是否自交

我有许多路线,每一条都由其许多点定义,这些点又由相应的地面军事系统坐标(纬度、经度)定义。我试图找到一个高效的Java实现来确定哪些线是自交的,我被称为JTS

这就是我想做的:

public boolean intersects(List<GcsNode> nodes) {

       Coordinate[] sequence = new Coordinate[route.size()];
       for (int i = 0; i < nodes.size(); i++) {
           sequence[i] = toCartesian(nodes.get(i).latitude(), nodes.get(i).longitude());
       }

       GeometryFactory factory = new GeometryFactory();
       return !factory.createLineString(sequence).isSimple();

}

public static final double DIST = 6371.0;


public Coordinate toCartesian(double latitude, double longitude) {

       return new Coordinate(DIST * Math.cos(latitude) * Math.cos(longitude),
                DIST * Math.cos(latitude) * Math.sin(longitude));
}

不幸的是,intersects方法总是返回true,无论路径是否自相交。有人知道我做错了什么吗


共 (0) 个答案