Having two points and a distance, I am trying to compute the azimuth and then to recompute back one of the points.
However, the distance between the computed point and the original point is more then 50 meters, which is quite a big error.
Here is the code:
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();
}
}
The output is:
Azimuth=44.97189638988797
computedEndPoint=Point2D.Double[-4.00014170719737, 41.49715519864095]
Distance=53.17698966547863
I expect the computedEndPoint to be quite similar (if not exactly) to declared end point from the beginning. And the distance between these two points to be close to zero.
Now my question is: what am I doing wrong? Or is there some bug in the GeodedicCalculator?