15 lines
519 B
Text
15 lines
519 B
Text
with javascript_semantics
|
|
constant MER = 6371, -- mean earth radius, authalic(km)
|
|
--constant MER = 6372.8, -- mean earth radius, average(km)
|
|
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 %.10f km (%.10f miles)\n",{d,d/1.609344})
|