3

For all the math geniuses out there...given two lat/lon points (point A and point B), what is the simplest way to find the vector needed to reach point B from point A. For example, the vector needed to reach 36, -85 from 36, -82 would be 270°. I am not entirely sure if "vector" is the technically correct term so if there is a more accurate term, comment and let me know. The fact that the earth is a sphere is throwing me off...I feel as if I could tackle this problem if given a plane but the sphere complicates it too much for me. A chunk of code would be ideal but a simple algorithm that I can translate into code myself is perfectly fine also.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Brandon Schmidt
  • 169
  • 1
  • 2
  • 13

1 Answers1

3

What you're looking for is the initial bearing (or forward azimuth), which if followed in a straight line along a great-circle arc will take you from the start point to the end point.

Here is some simple JavaScript from this link:

var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
        Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
var brng = Math.atan2(y, x).toDeg();

The above link has a wealth of useful information beyond this for related calculations.

As your question states, this is the simplest method - since the Earth is not a true sphere this calculation will not be 100% accurate, but it is a close approximation.

Radar
  • 10,659
  • 9
  • 60
  • 113
  • If this is accurate within a few degrees that is fine. In the final product, this will be indiscernible due to the affects of pixel rounding. I'll try this out...looks promising! – Brandon Schmidt Dec 05 '13 at 23:13
  • If your tolerance is really "a few degrees" (though i suspect it's a bit tighter) then the spherical earth assumption will be plenty good enough for you. – Martin F Dec 06 '13 at 01:05