How to resolve the algorithm Haversine formula step by step in the clojure programming language
How to resolve the algorithm Haversine formula step by step in the clojure programming language
Table of Contents
Problem Statement
The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical "triangles".
Implement a great-circle distance function, or use a library function, to show the great-circle distance between:
Most of the examples below adopted Kaimbridge's recommended value of 6372.8 km for the earth radius. However, the derivation of this ellipsoidal quadratic mean radius is wrong (the averaging over azimuth is biased). When applying these examples in real applications, it is better to use the mean earth radius, 6371 km. This value is recommended by the International Union of Geodesy and Geophysics and it minimizes the RMS relative error between the great circle and geodesic distance.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Haversine formula step by step in the clojure programming language
Source code in the clojure programming language
(defn haversine
[{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}]
(let [R 6372.8 ; kilometers
dlat (Math/toRadians (- lat2 lat1))
dlon (Math/toRadians (- lon2 lon1))
lat1 (Math/toRadians lat1)
lat2 (Math/toRadians lat2)
a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2))) (* (Math/sin (/ dlon 2)) (Math/sin (/ dlon 2)) (Math/cos lat1) (Math/cos lat2)))]
(* R 2 (Math/asin (Math/sqrt a)))))
(haversine {:latitude 36.12 :longitude -86.67} {:latitude 33.94 :longitude -118.40})
;=> 2887.2599506071106
You may also check:How to resolve the algorithm Hello world/Text step by step in the Pascal programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the E programming language
You may also check:How to resolve the algorithm Variadic function step by step in the BASIC programming language
You may also check:How to resolve the algorithm Vampire number step by step in the Clojure programming language
You may also check:How to resolve the algorithm Spinning rod animation/Text step by step in the NS-HUBASIC programming language