How to resolve the algorithm Angle difference between two bearings step by step in the Clojure programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Angle difference between two bearings step by step in the Clojure programming language

Table of Contents

Problem Statement

Finding the angle between two bearings is often confusing.[1]

Find the angle which is the result of the subtraction b2 - b1, where b1 and b2 are the bearings. Input bearings are expressed in the range   -180   to   +180   degrees. The  result  is also expressed in the range   -180   to   +180   degrees.

Compute the angle for the following pairs:

Allow the input bearings to be any (finite) value.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Angle difference between two bearings step by step in the Clojure programming language

Source code in the clojure programming language

(defn angle-difference [a b]
  (let [r (mod (- b a) 360)]
    (if (>= r 180)
      (- r 360)
      r)))

(angle-difference 20 45)  ; 25
(angle-difference -45 45) ; 90
(angle-difference -85 90) ; 175
(angle-difference -95 90) ; -175
(angle-difference -70099.74 29840.67) ; -139.59


  

You may also check:How to resolve the algorithm Pick random element step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Terminal control/Display an extended character step by step in the BASIC programming language
You may also check:How to resolve the algorithm Bioinformatics/base count step by step in the Delphi programming language
You may also check:How to resolve the algorithm Exceptions/Catch an exception thrown in a nested call step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Factorial step by step in the PL/0 programming language