Skip to content

Instantly share code, notes, and snippets.

@mlusiak
Created April 22, 2017 23:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlusiak/031d81a94c3302bb6be9068c8bc29345 to your computer and use it in GitHub Desktop.
Save mlusiak/031d81a94c3302bb6be9068c8bc29345 to your computer and use it in GitHub Desktop.
defmodule Flightlog.Math do
def greatCircle(a,b) do
lat1 = elem(a, 0)
lon1 = elem(a, 1)
lat2 = elem(b, 0)
lon2 = elem(b, 1)
rlat1 = :math.pi * lat1 / 180.0
rlat2 = :math.pi * lat2 / 180.0
theta = lon1 - lon2
rtheta = :math.pi * theta / 180.0
degDistance = :math.acos(:math.sin(rlat1) * :math.sin(rlat2) +
:math.cos(rlat1) * :math.cos(rlat2) * :math.cos(rtheta))
earthRadius = 6371.0
degDistance * earthRadius
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment