How to resolve the algorithm Haversine formula step by step in the Raven programming language
How to resolve the algorithm Haversine formula step by step in the Raven 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 Raven programming language
Source code in the raven programming language
define PI
-1 acos
define toRadians use $degree
$degree PI * 180 /
define haversine use $lat1, $lon1, $lat2, $lon2
6372.8 as $R
# In kilometers
$lat2 $lat1 - toRadians as $dLat
$lon2 $lon1 - toRadians as $dLon
$lat1 toRadians as $lat1
$lat2 toRadians as $lat2
$dLat 2 / sin
$dLat 2 / sin *
$dLon 2 / sin
$dLon 2 / sin *
$lat1 cos *
$lat2 cos * + as $a
$a sqrt asin 2 * as $c
$R $c *
}
-118.40 33.94 -86.67 36.12 haversine "haversine: %.15g\n" print
You may also check:How to resolve the algorithm Extreme floating point values step by step in the Tcl programming language
You may also check:How to resolve the algorithm Mouse position step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Check output device is a terminal step by step in the Ruby programming language
You may also check:How to resolve the algorithm Draw a pixel step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Monty Hall problem step by step in the Scala programming language