Skip to content

Improve short-distance accuracy of Andoyer inverse#1461

Open
mjacobse wants to merge 1 commit intoboostorg:developfrom
mjacobse:improve_andoyer_inverse_accuracy
Open

Improve short-distance accuracy of Andoyer inverse#1461
mjacobse wants to merge 1 commit intoboostorg:developfrom
mjacobse:improve_andoyer_inverse_accuracy

Conversation

@mjacobse
Copy link
Copy Markdown

@mjacobse mjacobse commented Apr 27, 2026

Use haversine formula instead of law of cosines to avoid numerical loss of precision for close points as suggested in #1217.

This has the side-effect of returning non-zero azimuths for smaller angles than before, which results in quite inaccurate non-zero reduced length and geodesic scale values too. To fix this, division by the cosine of the latitudes is changed to be done implicitly within atan2, which together with use of the haversine formula improves accuracy for all result values.

I planned to add tests for very close points like {8.81, 53.08}, {8.81000001, 53.08} to inverse_cases.hpp, since Andoyer returns a distance of about 9cm for such examples before this change, which has a very large relative error. Unfortunately the other formulas (especially Thomas) have some issues with examples like that too, so I could not easily get such tests to pass. Suggestions would be welcome.

The following plots (generated using a simple test executable and a Python script, see mjacobse@d2930ae) show the errors of the different quantities compared to GeographicLib for many randomly generated pairs of points depending on the order of magnitude of the distance between them (top row absolute error, bottom row relative error. red before these changes, green after):

distance:
distance

azimuth:
azimuth

reverse_azimuth:
reverse_azimuth

reduced_length:
reduced_length

geodesic_scale:
geodesic_scale

Use haversine formula instead of law of cosines to avoid numerical loss
of precision for close points as suggested in boostorg#1217.

This had the side-effect of returning non-zero azimuths for smaller
angles than before, which resulted in quite inaccurate non-zero reduced
length and geodesic scale values too. To fix this, division by the
cosine of the latitudes was changed to be done implicitly within atan2,
which together with use of the haversine formula improves accuracy for
all result values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant