Skip to content

Instantly share code, notes, and snippets.

@cocomoff
Created February 20, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocomoff/0807e61c9f05ae1e65b2f4d99bc9915d to your computer and use it in GitHub Desktop.
Save cocomoff/0807e61c9f05ae1e65b2f4d99bc9915d to your computer and use it in GitHub Desktop.
Computing Ground Distance on Earth from Latitude/Longtitude Point (e.g., http://www.nhc.noaa.gov/gccalc.shtml)
R = 6371000 # Radius of the Earth
S1 = Point(35.18028,136.90667) # Nagoya
S2 = Point(35.68944,139.69167) # Tokyo
# ground distance
function dG(Si::Point, Sj::Point)
φi, λi = deg2rad(Si.φ), deg2rad(Si.λ)
φj, λj = deg2rad(Sj.φ), deg2rad(Sj.λ)
v1 = sin( (φj - φi) / 2 )
v2 = sin( (λj - λi) / 2 )
return 2 * R * asin(sqrt( v1^2 + cos(φi) * cos(φj) * v2^2 ))
end
println("Example dG = $(dG(S1, S2)/1000) [km]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment