How to resolve the algorithm Haversine formula step by step in the ERRE programming language
How to resolve the algorithm Haversine formula step by step in the ERRE 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 ERRE programming language
Source code in the erre programming language
% Implemented by Claudio Larini
PROGRAM HAVERSINE_DEMO
!$DOUBLE
CONST DIAMETER=12745.6
FUNCTION DEG2RAD(X)
DEG2RAD=X*π/180
END FUNCTION
FUNCTION RAD2DEG(X)
RAD2DEG=X*180/π
END FUNCTION
PROCEDURE HAVERSINE_DIST(TH1,PH1,TH2,PH2->RES)
LOCAL DX,DY,DZ
PH1=DEG2RAD(PH1-PH2)
TH1=DEG2RAD(TH1)
TH2=DEG2RAD(TH2)
DZ=SIN(TH1)-SIN(TH2)
DX=COS(PH1)*COS(TH1)-COS(TH2)
DY=SIN(PH1)*COS(TH1)
RES=ASN(SQR(DX^2+DY^2+DZ^2)/2)*DIAMETER
END PROCEDURE
BEGIN
HAVERSINE_DIST(36.12,-86.67,33.94,-118.4->RES)
PRINT("HAVERSINE DISTANCE: ";RES;" KM.")
END PROGRAM
You may also check:How to resolve the algorithm Forward difference step by step in the C programming language
You may also check:How to resolve the algorithm Day of the week step by step in the Befunge programming language
You may also check:How to resolve the algorithm Vector step by step in the Factor programming language
You may also check:How to resolve the algorithm URL encoding step by step in the Haskell programming language
You may also check:How to resolve the algorithm Periodic table step by step in the Julia programming language