How to resolve the algorithm Haversine formula step by step in the Common Lisp programming language
How to resolve the algorithm Haversine formula step by step in the Common Lisp 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 Common Lisp programming language
Source code in the common programming language
(defparameter *earth-radius* 6372.8)
(defparameter *rad-conv* (/ pi 180))
(defun deg->rad (x)
(* x *rad-conv*))
(defun haversine (x)
(expt (sin (/ x 2)) 2))
(defun dist-rad (lat1 lng1 lat2 lng2)
(let* ((hlat (haversine (- lat2 lat1)))
(hlng (haversine (- lng2 lng1)))
(root (sqrt (+ hlat (* (cos lat1) (cos lat2) hlng)))))
(* 2 *earth-radius* (asin root))))
(defun dist-deg (lat1 lng1 lat2 lng2)
(dist-rad (deg->rad lat1)
(deg->rad lng1)
(deg->rad lat2)
(deg->rad lng2)))
You may also check:How to resolve the algorithm Plot coordinate pairs step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Host introspection step by step in the Nim programming language
You may also check:How to resolve the algorithm Compiler/lexical analyzer step by step in the Go programming language
You may also check:How to resolve the algorithm Set right-adjacent bits step by step in the F# programming language
You may also check:How to resolve the algorithm Currying step by step in the Factor programming language