Skip to content

Instantly share code, notes, and snippets.

@sduckett
Created October 1, 2015 02:22
Show Gist options
  • Save sduckett/862c3985bd72633229ad to your computer and use it in GitHub Desktop.
Save sduckett/862c3985bd72633229ad to your computer and use it in GitHub Desktop.
Some Clojure with a lot of Greek letters.
(defn haversine
"The haversine distance between two geographical points 1 and 2;
see <https://en.wikipedia.org/wiki/Haversine_formula>"
[p1 p2]
(let [φ1 (p1 :lat)
λ1 (p1 :lon)
φ2 (p2 :lat)
λ2 (p2 :lon)
Δλ (Math/toRadians (- λ2 λ1))
Δφ (Math/toRadians (- φ2 φ1))
ϴ (+ (Math/pow (Math/sin (/ Δφ 2)) 2)
(* (Math/cos (Math/toRadians φ1))
(Math/cos (Math/toRadians φ2))
(Math/pow (Math/sin (/ Δλ 2)) 2)))
Δσ (* 2 (Math/asin (Math/sqrt ϴ)))]
(* Δσ RADIUS-OF-EARTH-IN-METERS)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment