Sorry, an error occurred while loading the content.
Browse Groups

• ## Re: [mitab] Distance and Bearing calculation using WGS84 Ellipsoid parameters

(2)
• NextPrevious
• ... For Distance I use the built-in MapBasic Distance function. Bearing is: ====================================================================== function
Message 1 of 2 , Oct 31, 2003
View Source
On 31 Oct 2003 at 15:28, James Cornelius, PE <mitab@yahoogroups.com> wrote:

> Has anyone written a Mapbasic routine that cacluates distance and bearing
> using WGS84 datum Ellipsoid parameters.

For Distance I use the built-in MapBasic "Distance" function.

Bearing is:

'======================================================================
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
Your message has been successfully submitted and would be delivered to recipients shortly.
• Changes have not been saved
Press OK to abandon changes or Cancel to continue editing
• Your browser is not supported
Kindly note that Groups does not support 7.0 or earlier versions of Internet Explorer. We recommend upgrading to the latest Internet Explorer, Google Chrome, or Firefox. If you are using IE 9 or later, make sure you turn off Compatibility View.