mapbox / cheap-ruler

Fast approximations for common geodesic measurements 🌐
https://www.mapbox.com/blog/cheap-ruler/
ISC License
417 stars 32 forks source link

precision compared to haversine (vincenty as reference) #18

Closed kaynut closed 8 years ago

kaynut commented 8 years ago

First of all: this fast approx is really fast: I really like it ! Thanks!

But I can't really proof the statements to its precision, stated at https://www.mapbox.com/blog/cheap-ruler/. At least when it comes to calculating points by a startingpoint and a specified distance and angle.

(To give you some idea, what I need: I need to calculate lots of lonlats from a lonlat at different distances and angle: For me distances up to 150km-200km are of interest)

Using vincenty as a reference, all my calculations leave me with a significantly larger error, compared to those of haversine - starting in mid-latitudes,say at 40-60km - and not after some 100s miles.

I've made a fiddle to visualize this. https://jsfiddle.net/badorties/awc44k9L/15/

The question: Am I doing something wrong? Short answer would be very appreciated.

kaynut commented 8 years ago

Again on the precison of the cheap-ruler-function, calculating lonlat from lonlat,distance bearing:

After some thinking and playing around, it becomes more or less obvious, that an approximation using static scalers per latitude (like the cheap ruler does: kx,ky) has to produce a quite rapidly growing error.

And I would expect that this error will exceed the tolerance for at least some usecases beyond 20-40km (and nearer to the poles).

A big thank anyway for sharing this extremly efficent way to calculate those coefficients!
I really liked that part and - within bounds this is surely the way I would take!

mourner commented 8 years ago

Sorry for a late reply — yeah, seems like the error is much higher for the destination method compared to the distance one, but that's a design flaw, not something that can be fixed in the library. It will probably be OK to use for smaller distances.