有两个点和一个距离,我试图计算方位角,然后重新计算其中一个点。
但是计算点到原点的距离超过50米,误差很大。
这是代码:
public static void main(String[] args) {
double startLongitude = -5.1085;
double startLatitude = 40.6682667;
double endLongitude = -4.000597497067124;
double endLatitude = 41.49682079962159;
double distance = 130947.51;
try {
CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
GeodeticCalculator calculator = new GeodeticCalculator(crs);
calculator.setStartingGeographicPoint(startLongitude, startLatitude);
calculator.setDestinationGeographicPoint(endLongitude, endLatitude);
double azimuth = calculator.getAzimuth();
System.out.println("Azimuth=" + azimuth);
calculator = new GeodeticCalculator(crs);
calculator.setStartingGeographicPoint(startLongitude, startLatitude);
calculator.setDirection(azimuth, distance);
Point2D computedEndPoint = calculator.getDestinationGeographicPoint();
System.out.println("computedEndPoint=" + computedEndPoint);
calculator = new GeodeticCalculator(crs);
calculator.setStartingGeographicPoint(endLongitude, endLatitude);
calculator.setDestinationGeographicPoint(computedEndPoint);
distance = calculator.getOrthodromicDistance();
System.out.println("Distance=" + distance);
} catch (FactoryException e) {
e.printStackTrace();
}
}
输出是:
方位角=44.97189638988797
computedEndPoint=Point2D.Double[-4.00014170719737, 41.49715519864095]
距离=53.17698966547863
我希望 computedEndPoint 从一开始就与声明的终点非常相似(如果不完全一样)。并且这两点之间的距离要接近于零。
现在我的问题是:我做错了什么?或者 GeodedicCalculator 中是否存在一些错误?