 
 (def front-coordinate (nth coordinates front-segment))
 
-(def vehicle-bearing (bearing front-coordinate back-coordinate))
-
 (def distance-to-front-segment (- back-distance meters-away))
 
-;(pprint coordinates)
+(def target-to-front-segment (- meters-away front-distance))
 
-(interpolate-coordinates front-coordinate distance-to-front-segment vehicle-bearing)
+;;(pprint coordinates)
+
 
 (defroutes routes
   (POST "/rush-hour/api/triangulate/edn" {:keys [body]}


(defn haversine [a b]
  (let [lat1 (:lat a)
        lat2 (:lat b)
        lon1 (:long a)
        lon2 (:long b)
        R 6372800
        dlat (Math/toRadians (- lat2 lat1))

                (Math/cos lat1) (Math/cos lat2)))]
    (* R 2 (Math/asin (Math/sqrt a)))))

(defn interpolate-coordinates [a b c d]
  (let [lat1 (:lat a)
        lon1 (:long a)
        lat2 (:lat b)
        lon2 (:long b)
        lat-diff (- lat2 lat1)
        lon-diff (- lon2 lon1)
        theta (Math/atan (/ lon-diff lat-diff))
        x1 (* (Math/cos theta) d)
        y1 (* (Math/sin theta) d)
        x2 (* (Math/cos theta) c)
        y2 (* (Math/sin theta) c)
        x-ratio (* (/ x1 x2) lat-diff)
        y-ratio (* (/ y1 y2) lon-diff)]
    {:lat (+ lat1 x-ratio) :long (+ lon1 y-ratio)}))

(defn take-segments
  ([segments distance] (take-segments segments distance 0 0))
