2

I am trying to calculate bearing between two lat/lon points as given in this link. I see that the bearing we get initially using the below equation is initial bearing.

    public static double GetBearing(double latitude1, double longitude1, double latitude2, double longitude2)
        {
            var lat1 = ToRadians(latitude1);
            var lat2 = ToRadians(latitude2);
            var longdiff = ToRadians(longitude1 - longitude2);
            var X = Math.Cos(lat2) * Math.Sin(longdiff);
            var Y = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(longdiff);
            var bearing =ToDegrees(Math.Atan2(X, Y));
            return (bearing+360)%360;
        }

It is given that

For final bearing, simply take the initial bearing from the end point to the start point and reverse it (using θ = (θ+180) % 360).

I am confused about the difference between initial bearing and final bearing. What is this initial and final bearing and which bearing should we take as the final answer for bearing between two points.

Sree
  • 973
  • 2
  • 14
  • 32

3 Answers3

5

The bearing is the angle between direction along the shortest path to destination and direction to North. The reason we have initial and final one is that we live on sphere, so the shortest path is geodesic line. It is a straight line on globe, bit if you draw it on flat map - it will be a curve.

There are two ways to think about it. Thinking on flat map: as you travel from A to B, this curve changes direction slightly, so the angle between this line and North changes, i.e. bearing changes.

Or you can think on sphere, and then think about triangle A - B - North Pole. The bearing is angle between between AB and appropriate meridian. Initial bearing is angle between AB and meridian crossing A. Final one is angle between AB and meridian crossing B. They are different.

The single "final answer" bearing only makes sense when distance between A and B is short. Then the curvature of Earth does not matter much, and the initial and final bearings are very close to each other, so depending on precision needed one can talk about single bearing.

Michael Entin
  • 7,189
  • 3
  • 21
  • 26
1

FYI: bearing and many related computations are implemented in the R package geosphere The bearing function returns the initial bearing, but you can invert the coordinates to get the final bearing.

library(geosphere)
bearing(cbind(0,0),cbind(20,20))
#[1] 43.4035
finalb <- bearing(cbind(20,20),cbind(0,0)) 
(finalb + 180) %% 360
#[1] 46.9656

(these results should be more precise than the ones you get with algorithm you refer to)

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • There's also a `finalBearing` function that can be used instead of inverting the coordinates. – Joakim Apr 17 '21 at 13:37
0

def bearing(lat1, lon1, lat2, lon2): # Convert latitude and longitude to radians lat1 = math.radians(lat1) lon1 = math.radians(lon1) lat2 = math.radians(lat2) lon2 = math.radians(lon2)

y = math.sin(lon2-lon1) * math.cos(lat2)
x = math.cos(lat1)*math.sin(lat2) - math.sin(lat1)*math.cos(lat2)*math.cos(lon2-lon1)
initial_bearing = math.degrees(math.atan2(y, x))
final_bearing = (initial_bearing + 180) % 360 if initial_bearing < 180 else (initial_bearing - 180) % 360
return initial_bearing, final_bearing
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 24 '23 at 03:05