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

Published on 12 May 2024 09:40 PM

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

Source code in the racket programming language

#lang racket
(require math)
(define earth-radius 6371)

(define (distance lat1 long1 lat2 long2)
  (define (h a b) (sqr (sin (/ (- b a) 2))))
  (* 2 earth-radius 
     (asin (sqrt (+ (h lat1 lat2) 
                    (* (cos lat1) (cos lat2) (h long1 long2)))))))

(define (deg-to-rad d m s) 
  (* (/ pi 180) (+ d (/ m 60) (/ s 3600))))

(distance (deg-to-rad 36  7.2 0) (deg-to-rad  86 40.2 0)
          (deg-to-rad 33 56.4 0) (deg-to-rad 118 24.0 0))


  

You may also check:How to resolve the algorithm Longest increasing subsequence step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the Batch File programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the Elixir programming language
You may also check:How to resolve the algorithm Superellipse step by step in the Stata programming language
You may also check:How to resolve the algorithm Yellowstone sequence step by step in the Arturo programming language