How to resolve the algorithm Haversine formula step by step in the Sidef programming language
How to resolve the algorithm Haversine formula step by step in the Sidef 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 Sidef programming language
Source code in the sidef programming language
class EarthPoint(lat, lon) {
const earth_radius = 6371 # mean earth radius
const radian_ratio = Num.pi/180
# accessors for radians
method latR { self.lat * radian_ratio }
method lonR { self.lon * radian_ratio }
method haversine_dist(EarthPoint p) {
var arc = EarthPoint(
self.lat - p.lat,
self.lon - p.lon,
)
var a = Math.sum(
(arc.latR / 2).sin**2,
(arc.lonR / 2).sin**2 *
self.latR.cos * p.latR.cos
)
earth_radius * a.sqrt.asin * 2
}
}
var BNA = EarthPoint.new(lat: 36.12, lon: -86.67)
var LAX = EarthPoint.new(lat: 33.94, lon: -118.4)
say BNA.haversine_dist(LAX) #=> 2886.444442837983299747157823945746716...
You may also check:How to resolve the algorithm Thue-Morse step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the Julia programming language
You may also check:How to resolve the algorithm Long year step by step in the C programming language
You may also check:How to resolve the algorithm Literals/String step by step in the M4 programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the MIPS Assembly programming language