GREAT CIRCLE SAILING
The great circle distance in degrees between Point1 (lat1, lon1) and Point2 (lat2, lon2) is easily calculated:
cos(D)= Sin(lat1) * Sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1)
or what is the same:
D= arccos(Sin(lat1) * Sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1))
In this paper we assume the following signs N=+, S=-, W=+, E=- .
cos(D) will always fall in the range -1 < cos(D) < 1 and (D) will be a positive angle: 0° < D < 180°. You can use a formula that will use the arctan function but this will give a result in the -90° to +90° range and you need to add 180° if the result is negative.
The azimuth or initial course from point 1 (origin) to point 2 (destination) Zn can also be easily calculated. Zn is always measured from North to East from 0° to 360°. First we calculate Z. If we have considered West longitudes as positive we use this formula:
(If we had considered East longitudes as being positive we would need to change the sign on one side of this equation.)
The function ATAN( ) returns a value between -90° and +90° so Z needs to be adjusted to the right quadrant in order to obtain Zn: 0° < Zn < 360°
If sign(sin(Z)) = sign(sin(lon2-lon1)) Then Zn = Z + 180 Else, If Z < 0 Then Zn = Z + 360 Else Zn = Z
Zn = Z + 90 * (1 + sign( sin(lon2-lon1) * sin(Z) ) )