Created
May 13, 2016 20:35
-
-
Save tobyprivett/ca105c7e08f40486feb4d7754bc52472 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// from https://rosettacode.org/wiki/Haversine_formula#Elixir | |
defmodule Haversine do | |
@v :math.pi / 180 | |
@r 6372.8 # km for the earth radius | |
def distance({lat1, long1}, {lat2, long2}) do | |
dlat = :math.sin((lat2 - lat1) * @v / 2) | |
dlong = :math.sin((long2 - long1) * @v / 2) | |
a = dlat * dlat + dlong * dlong * :math.cos(lat1 * @v) * :math.cos(lat2 * @v) | |
@r * 2 * :math.asin(:math.sqrt(a)) | |
end | |
end | |
bna = {36.12, -86.67} | |
lax = {33.94, -118.40} | |
IO.puts Haversine.distance(bna, lax) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment