How to resolve the algorithm Haversine formula step by step in the UBASIC programming language
How to resolve the algorithm Haversine formula step by step in the UBASIC 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 UBASIC programming language
Source code in the ubasic programming language
10 Point 7 'Sets decimal display to 32 places (0+.1^56)
20 Rf=#pi/180 'Degree -> Radian Conversion
100 ?Using(,7),.DxH(36+7.2/60,-(86+40.2/60),33+56.4/60,-(118+24/60));" km"
999 End
1000 '*** Haversine Distance Function ***
1010 .DxH(Lat_s,Long_s,Lat_f,Long_f)
1020 L_s=Lat_s*rf:L_f=Lat_f*rf:LD=L_f-L_s:MD=(Long_f-Long_s)*rf
1030 Return(12745.6*asin( (sin(.5*LD)^2+cos(L_s)*cos(L_f)*sin(.5*MD)^2)^.5))
'' ''
Run
2887.2599506 km
OK
You may also check:How to resolve the algorithm History variables step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Averages/Pythagorean means step by step in the C# programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the SQL programming language
You may also check:How to resolve the algorithm Function prototype step by step in the Oforth programming language
You may also check:How to resolve the algorithm Combinations step by step in the Lobster programming language