MapBasic Code. Copy/Paste if needed.
|
include "GC_Constants.def" include "GC_Azimuth.def" '====================================================================== function GreatCircleAzimuth ( byval fLon0 as float, 'Origin longitude byval fLat0 as float, 'Origin latitude byval fLon1 as float, 'Destination longitude byval fLat1 as float) 'Destination latitude as float 'Azimuth bearing 'Calculates the azimuth that the destination point bears to the 'origin. Azimuth is returned as decimal degrees. '---------------------------------------------------------------------- dim a, b as float dim fAdjust as float dim lat0, lon0, lat1, lon1 as float lat0 = fLat0 * DEG2RAD lon0 = fLon0 * DEG2RAD lat1 = fLat1 * DEG2RAD lon1 = fLon1 * DEG2RAD a = cos(lat1) * sin(lon1 - lon0) b = cos(lat0) * sin(lat1) - sin(lat0) * cos(lat1) * cos(lon1 - lon0) 'perform quadrant adjustment if a = 0 and b = 0 then GreatCircleAzimuth = 0 exit function end if if b = 0 then if a < 0 then GreatCircleAzimuth = 270 else GreatCircleAzimuth = 90 end if exit function end if if b < 0 then fAdjust = PI else if a < 0 then fAdjust = 2 * PI else fAdjust = 0 end if end if GreatCircleAzimuth = (atn(a/b) + fAdjust) * RAD2DEG end function |