
Ellipsoid distance on Earth - longdefeat
https://www.johndcook.com/blog/2018/11/24/spheroid-distance/
======
avs733
A funny example of this in practice happened a few years ago during the United
Airlines and Continental Airlines merger.

When they switched computer systems, _somehow_ they switched the method they
used to calculate the distances between cities for their frequent flyer
program. Before the merger, both companies used the ellipsoid method. During
the computer systems cutover, the method suddenly changed to a spherical
approximation. They also used an incorrect

The difference resulted in shorting flyers of a few (I think the most I saw
was 40) frequent flyer miles per leg. They got caught within a couple days and
'fixed' the 'accidental' change. One of those things they seemed to hope no
individual would catch but that over many many flyers would add up to a
significant cost savings.

------
jillesvangurp
The alternatives are either using the pythagoras algorithm, which only makes
sense for short distances (unless you are a flat earth believer) or the
haversine algorithm:
[https://en.wikipedia.org/wiki/Haversine_formula](https://en.wikipedia.org/wiki/Haversine_formula).
Haversine is fine unless you really need super accurate results. The shorter
the distance the less of an issue this is.

If you are doing simple distance searches on a map with small radiuses, use
whatever is good enough. I've used pythagoras for this in the past as part of
a ranking formula as it is a lot cheaper to do that and it does not have to be
super accurate.

------
jabberthemutt
Why does this use all the mathematical function from scipy instead of the
built-in math? Are there significant benefits to that?

~~~
snops
They are actually from numpy, scipy just re-exports them, so they work with
numpy arrays which the built in maths would not. I guess the author writes a
lot of scientific code, so is in the habit of using them.

Numpy arrays are much faster than python lists etc for maths and matrix
operations, (e.g. multiply this 1000 element vector by 2), which are common in
scientific and engineering code.

[https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/...](https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.sin.html)

~~~
johndcook
Yes, the author does write a lot of scientific code and is in the habit of
using SciPy. -- the author :)

------
pmiller2
For a lot of use cases, the error in using the spherical approximation is
small enough that it doesn’t matter. For instance, measuring distance between
two points in the same city, you can happily use the shorter function and not
worry about it.

~~~
thibautg
Most GIS applications have this functionality (distance on ellipsoid) built-
it.

For local distance measuring it is generally better and easier to use a
projected coordinates system (where units are meters/miles instead of
degrees).

But if you are using a software without GIS functions (excel?) and only have a
dataset with lat/long coordinates, then it is easier to use the short formula
;-)

------
mirimir
This is an easy-to-implement approach, with a great explanation.

~~~
sorenjan
If you're going to implement distance measuring it's probably better to use a
package like GeoPy instead.

[https://geopy.readthedocs.io/en/stable/#module-
geopy.distanc...](https://geopy.readthedocs.io/en/stable/#module-
geopy.distance)

~~~
jacobolus
GeoPy’s implementation is based on Karney’s work,
[https://geographiclib.sourceforge.io/](https://geographiclib.sourceforge.io/)
[https://arxiv.org/abs/1109.4448](https://arxiv.org/abs/1109.4448)

