[GIS] How to determine vector between two lat/lon points

azimuthgreat circlelatitude longitudemathematics

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.

Best Answer

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.