RosettaCodeData/Task/Haversine-formula/LiveCode/haversine-formula-1.livecode

28 lines
756 B
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function radians n
return n * (3.1415926 / 180)
end radians
function haversine lat1, lng1, lat2, lng2
local radiusEarth
local lat3, lng3
local lat1Rad, lat2Rad, lat3Rad
local lngRad1, lngRad2, lngRad3
local haver
put 6372.8 into radiusEarth
put (lat2 - lat1) into lat3
put (lng2 - lng1) into lng3
put radians(lat1) into lat1Rad
put radians(lat2) into lat2Rad
put radians(lat3) into lat3Rad
put radians(lng1) into lngRad1
put radians(lng2) into lngRad2
put radians(lng3) into lngRad3
put (sin(lat3Rad/2.0)^2) + (cos(lat1Rad)) \
* (cos(lat2Rad)) \
* (sin(lngRad3/2.0)^2) \
into haver 
return (radiusEarth * (2.0 * asin(sqrt(haver))))
end haversine