# How to determine vector between two lat/lon points

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.

• You're looking for a great circle distance calculation. Take a look at this question or this question. Commented Dec 5, 2013 at 22:52
• The Earth isn't a sphere -- it's a spheroid, which will mess up the accuracy of spherical trig. The real solution is a partial differential equation, only solvable through iterative means. Commented Dec 5, 2013 at 23:03
• The direction (or "bearing") from (36,-85) to (36,-82) is not 270 degrees! It is actually a bit greater than that. Commented Dec 5, 2013 at 23:26
• If they're lat-lon coords, the bearing is just under 90°. If they're lon-lat coords, it is exactly 0°. Commented Dec 6, 2013 at 1:03

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.

• 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! Commented Dec 5, 2013 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. Commented Dec 6, 2013 at 1:05