adapted from the Great Circle Calculator written by Ed Williams (used with permission)
More information on Great Circle navigation can be found here.