Created
February 20, 2017 15:04
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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