How to resolve the algorithm Angle difference between two bearings step by step in the Action! 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 Action! 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 Action! programming language

Source code in the action! programming language

INCLUDE "H6:REALMATH.ACT"

INT FUNC AngleI(INT a1,a2)
  INT r

  r=a2-a1
  WHILE r>180 DO r==-360 OD
  WHILE r<-180 DO r==+360 OD
RETURN (r)

PROC TestI(INT a1,a2)
  INT r

  r=AngleI(a1,a2)
  PrintF("%I .. %I = %I%E",a1,a2,r)
RETURN

PROC AngleR(REAL POINTER r1,r2,r)
  REAL tmp,r180,rm180,r360

  ValR("180",r180)
  ValR("-180",rm180)
  ValR("360",r360)

  RealSub(r2,r1,r)
  WHILE RealGreaterOrEqual(r,r180)
  DO
    RealSub(r,r360,tmp) RealAssign(tmp,r)
  OD
  WHILE RealGreaterOrEqual(rm180,r)
  DO
    RealAdd(r,r360,tmp) RealAssign(tmp,r)
  OD
RETURN

PROC TestR(CHAR ARRAY s1,s2)
  REAL r1,r2,r

  ValR(s1,r1) ValR(s2,r2)
  AngleR(r1,r2,r)
  PrintR(r1) Print(" .. ") PrintR(r2)
  Print(" = ") PrintRE(r)
RETURN

PROC Main()
  Put(125) PutE() ;clear screen
  TestI(20,45)
  TestI(-45,45)
  TestI(-85,90)
  TestI(-95,90)
  TestI(-45,125)
  TestI(-45,145)
  TestR("29.4803","-88.6381")
  TestR("-78.3251","-159.036")
  TestR("-70099.74233810938","29840.67437876723")
  TestR("-165313.6666297357","33693.9894517456")
  TestR("1174.8380510598456","-154146.66490124757")
  TestR("60175.77306795546","42213.07192354373")
RETURN

  

You may also check:How to resolve the algorithm Sleep step by step in the Lang programming language
You may also check:How to resolve the algorithm Determine if a string is squeezable step by step in the Groovy programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the Ursala programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/PCG32 step by step in the Delphi programming language