Closed derhuerst closed 8 years ago
To obtain the distance use the distanceBetween()
function.
If you can assume that the planet is an ideal sphere, bearing is as simple as the following:
Math.atan2(p[1].lat - p[0].lat, p[1].lon - p[0].lon)
I hope that helps for now. Of course it'd be totally awesome if the library provided this functionality beyond the ideal sphere assumption.
I hope that helps for now. Of course it'd be totally awesome if the library provided this functionality beyond the ideal sphere assumption.
But the whole point of the library is to handle a non-ideal sphere, right?
@astro @derhuerst
But the whole point of the library is to handle a non-ideal sphere, right?
Correct, that is the assumption with this library. After finding some information on a great circle path for initial bearings at http://www.movable-type.co.uk/scripts/latlong.html realized that these calculations do not take into account the ellipsoid. Such a solution would not be suitable here.
Found a brilliant implementation of the Inverse problem described and coded in JavaScript here
This solution involves iteration over a handful of trigonometric functions so performance will be slower than your basic great circle implementations and actually I am re-evaluating the use of the Haversine formula for calculating distance after finding this.
Since we are taking into account the wgs-84 ellipsoid the preference is leaning towards accuracy over performance IMO, should have some updates soon as I now have a need for a bearingBetween()
function
fixed by e220fec355161d76bcb3a723efd998b5844e6ad6
I'd like to get the
bearing
fromcoordA
&coordB
and use it to calculate the position on a "2D" map.Right now, the library allows me to do
coordA, bearing, distance -> coordB
, but doingcoordA, coordB -> bearing, distance
is impossible.