uber / h3

Hexagonal hierarchical geospatial indexing system
https://h3geo.org
Apache License 2.0
4.92k stars 467 forks source link

Question: haversine distance algorithm #411

Open jamescooper-blis opened 3 years ago

jamescooper-blis commented 3 years ago

Hi,

Looking at the code, it seems the haversine algorithm used in [0] is faster (On My Machine) than the offical algorithm used in [1]. Is there reason it's not the official algorithm? Are there accuracy issues?

[0] https://github.com/uber/h3/blob/6c3c806ffbec16d32013bfa80ceec43b4c7513be/examples/distance.c#L39 [1] https://github.com/uber/h3/blob/6c3c806ffbec16d32013bfa80ceec43b4c7513be/src/h3lib/lib/geoCoord.c#L151

Thanks!

ajfriend commented 3 years ago

Interesting! I removed [0] because I couldn't find any references for the formula.

I tested two alternatives described here: https://www.movable-type.co.uk/scripts/latlong.html We ended up with the "Haversine" formula [1] on that page.

I recall doing some benchmarking, but not seeing any speed difference between the two, at least on my mac.

How are you doing your benchmarking?