How to resolve the algorithm Haversine formula step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Haversine formula step by step in the zkl 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 zkl programming language

Source code in the zkl programming language

haversine(36.12, -86.67, 33.94, -118.40).println();
 
fcn haversine(Lat1, Long1, Lat2, Long2){
   const R = 6372.8; 	// In kilometers;
   Diff_Lat  := (Lat2  - Lat1) .toRad();
   Diff_Long := (Long2 - Long1).toRad();
   NLat      := Lat1.toRad();
   NLong     := Lat2.toRad();
   A 	     := (Diff_Lat/2) .sin().pow(2) + 
                (Diff_Long/2).sin().pow(2) * 
		NLat.cos() * NLong.cos();
   C 	     := 2.0 * A.sqrt().asin();
   R*C;
}

  

You may also check:How to resolve the algorithm Search a list step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm CSV data manipulation step by step in the Aime programming language
You may also check:How to resolve the algorithm Van der Corput sequence step by step in the Action! programming language
You may also check:How to resolve the algorithm Straddling checkerboard step by step in the C programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the LOLCODE programming language