Haversine Formula
en.wikipedia.org
en.wikipedia.org
Also, another reference for both methods with calculators! Vicenty: http://www.movable-type.co.uk/scripts/latlong-vincenty.html Haversine: http://www.movable-type.co.uk/scripts/latlong.html
It has good implementations in C++, C# and Javascript.
=ACOS(COS(RADIANS(90−Selector::$Lat))×COS(RADIANS(90−N2))+SIN(RADIANS(90−Selector::$Lat))×SIN(RADIANS(90−N2))×COS(RADIANS(Selector::$Lon−O2)))×6371
("Selector" is a table title, I seem to remember - this is an Apple Numbers spreadsheet.)
6371 is a magic number which gives the result in kilometers.
The philosophy is that you can treat trigonometry as a triangle construction problem. You give me the specs of a triangle, and I can use physical tools like compasses, protractors and rulers to construct your triangle. This is similar to using trigonometry, except without any algebra involved, just construction tools. You can also use this philosophy to derive the algebraic formulas. When it came to formula derivation, I used the quaternions to simulate the physical construction, and I got out the formulas.
I'll provide more explanation later.
I wish trigonometry in secondary school had been taught more like this (geometrically) because it would have been good preparation for vector calculus, among other things.
https://github.com/jpatokal/openflights/blob/master/js/great...
There are a lot of interesting edge cases regarding routes that cross the dateline, the North Pole, etc. Most of the code was taken from Movable Type's incredible library of lat/long code:
How else would I know that I’ve travelled 2.7x to the moon in the last decade.
Mmmmmmm. Not magically converting meters to miles?
I dunno. I kind of think that one's on you, bud.
[1] https://gchq.github.io/CyberChef/#recipe=Haversine_distance(...
Then we had to implement hierarchical agglomerative clustering by hand, only using the dendrogram function from scikit-learn.
If you want to save storage space / bandwidth, you can use the stereographic projection onto a plane and then cut the precision of the floating-point numbers. Stereographic projection / inverse stereographic projection only requires 1 division per point.
Latitude/longitude is quite an inefficient and cumbersome way of representing points on a sphere, though it’s convenient if navigating using the stars.
Using lat/lon absolves you of storing projection metadata
“The definition must be accompanied with a specification of the ellipsoid.” etc.
I use it in my Captain's Log[0] application for Elite: Dangerous players, to show the distance your ship is to a target Lat/Lon location, amongst other handy navigation features.
Written in Python, using Qt4 and Pyside.
[0] https://captainslog.scarygliders.net/user-manuals/captains-l...