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
; Haversine formula | |
; a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) | |
; c = 2 ⋅ atan2( √a, √(1−a) ) | |
; d = R ⋅ c | |
; where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km); | |
(defn haversine | |
"Implementation of Haversine formula. Takes two sets of latitude/longitude pairs and returns the shortest great circle distance between them (in km)" | |
[{lon1 :lng lat1 :lat} {lon2 :lng lat2 :lat}] | |
(let [R 6378.137 ; Radius of Earth in km |
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
; "Reverse haversine" to derive lat/long from start point, bearing (degrees clockwise from north), & distance (km) | |
; φ2 = asin( (sin φ1 ⋅ cos δ) + (cos φ1 ⋅ sin δ ⋅ cos θ) ) | |
; λ2 = λ1 + atan2( sin θ ⋅ sin δ ⋅ cos φ1, cos δ − sin φ1 ⋅ sin φ2 ) | |
; where φ is latitude, λ is longitude, θ is the bearing (clockwise from north), δ is the angular distance d/R; d being the distance travelled, R the earth’s radius | |
(defn reverse-haversine | |
"Implementation of the reverse of Haversine formula. Takes one set of latitude/longitude as a start point, a bearing, and a distance, and returns the resultant lat/long pair." | |
[{lon :lng lat :lat bearing :bearing distance :distance}] | |
(let [R 6378.137 ; Radius of Earth in km | |
lat1 (Math/toRadians lat) |
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
(ns project.core | |
(:require [cognitect.transit :as transit]) | |
(:use kafka-clj.client :reload) | |
(:import [java.io ByteArrayInputStream ByteArrayOutputStream])) | |
;; Set up connector here | |
(let [data (ByteArrayOutputStream. 4096) | |
writer (transit/writer data :json)] | |
(transit/write writer link-difference) |
OlderNewer