 # Bearing and distance calculation methods

This page shows how the destination point is calculated in the Bearing and Distance Calculator given a starting point, bearing and distance.

A method is given for calculating the destination point for ellipsoid earth models using Vincenty's formula, and a second method is given to calculate the destination point for a spherical earth model. For both methods:

• Convert the starting point latitude 'lat1' (in the range -90 to 90) to radians.
lat1 = lat1 * PI/180
• Convert the starting point longitude 'lon1' (in the range -180 to 180) to radians.
lon1 = lon1 * PI/180
• Convert the bearing 'brg' (in the range 0 to 360) to radians.
brg = brg * PI/180

## Ellipsoid earth models

Note: the variable 'flat' below represents the earth's polar flattening used in various ellipsoid models. For the commonly used WGS-84, let flat = 298.257223563.

1. Given the distance s in meters, the semi-major axis 'a' in meters, the semi-minor axis 'b' in meters and the polar flattening 'flat'.
2. Calculate the destination point useing Vincenty's formula. Shortened variable names are used.
f = 1/flat
sb=sin(brg)
cb=cos(brg)
tu1=(1-f)*tan(lat1)
cu1=1/sqrt((1+tu1*tu1))
su1=tu1*cu1
s2=atan2(tu1, cb)
sa = cu1*sb
csa=1-sa*sa
us=csa*(a*a - b*b)/(b*b)
A=1+us/16384*(4096+us*(-768+us*(320-175*us)))
B = us/1024*(256+us*(-128+us*(74-47*us)))
s1=s/(b*A)
s1p = 2*PI
3. Loop through the following while condition is true.
while (abs(s1-s1p) > 1e-12)
cs1m=cos(2*s2+s1)
ss1=sin(s1)
cs1=cos(s1)
ds1=B*ss1*(cs1m+B/4*(cs1*(-1+2*cs1m*cs1m)- B/6*cs1m*(-3+4*ss1*ss1)*(-3+4*cs1m*cs1m)))
s1p=s1
s1=s/(b*A)+ds1
4. Continue calculation after the loop.
t=su1*ss1-cu1*cs1*cb
lat2=atan2(su1*cs1+cu1*ss1*cb, (1-f)*sqrt(sa*sa + t*t))
l2=atan2(ss1*sb, cu1*cs1-su1*ss1*cb)
c=f/16*csa*(4+f*(4-3*csa))
l=l2-(1-c)*f*sa* (s1+c*ss1*(cs1m+c*cs1*(-1+2*cs1m*cs1m)))
d=atan2(sa, -t)
finalBrg=d+2*PI
backBrg=d+PI
lon2 = lon1+l;
5. Convert lat2, lon2, finalBrg and backBrg to degrees
lat2 = lat2 * 180/PI
lon2 = lon2 * 180/PI
finalBrg = finalBrg * 180/PI
backBrg = backBrg * 180/PI
6. If lon2 is outside the range -180 to 180, add or subtract 360 to bring it back into that range.
7. If finalBrg or backBrg is outside the range 0 to 360, add or subtract 360 to bring them back into that range.

Note: the variables 'a', 'b' and 'flat' above have the following relationships:
b = a - (a/flat)
flat = a / (a - b)

## Spherical earth model

1. Given the distance 'dist' in miles or kilometers.
3. Convert distance to the distance in radians.
4. Calculate the destination coordinates.
lat2 = asin(sin(lat1)*cos(dist) + cos(lat1)*sin(dist)*cos(brg))
lon2 = lon1 + atan2(sin(brg)*sin(dist)*cos(lat1), cos(dist)-sin(lat1)*sin(lat2))
5. Calculate the final bearing and back bearing.
dLon = lon1-lon2
y = sin(dLon) * cos(lat1)
x = cos(lat2)*sin(lat1) - sin(lat2)*cos(lat1)*cos(dLon)
d=atan2(y, x)
finalBrg = d+PI
backBrg=d+2*PI
6. Convert lat2, lon2, finalBrg and backBrg to degrees
lat2 = lat2 * 180/PI
lon2 = lon2 * 180/PI
finalBrg = finalBrg * 180/PI
backBrg = backBrg * 180/PI
7. If lon2 is outside the range -180 to 180, add or subtract 360 to bring it back into that range.
8. If finalBrg or backBrg is outside the range 0 to 360, add or subtract 360 to bring them back into that range.