13 lines
425 B
Text
13 lines
425 B
Text
constant MER = 6371 -- mean earth radius(km)
|
|
constant DEG_TO_RAD = PI/180
|
|
|
|
function haversine(atom lat1, long1, lat2, long2)
|
|
lat1 *= DEG_TO_RAD
|
|
lat2 *= DEG_TO_RAD
|
|
long1 *= DEG_TO_RAD
|
|
long2 *= DEG_TO_RAD
|
|
return MER*arccos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(long2-long1))
|
|
end function
|
|
|
|
atom d = haversine(36.12,-86.67,33.94,-118.4)
|
|
printf(1,"Distance is %f km (%f miles)\n",{d,d/1.609344})
|