How to resolve the algorithm Averages/Mean angle step by step in the PicoLisp programming language
How to resolve the algorithm Averages/Mean angle step by step in the PicoLisp programming language
Table of Contents
Problem Statement
When calculating the average or mean of an angle one has to take into account how angles wrap around so that any angle in degrees plus any integer multiple of 360 degrees is a measure of the same angle. If one wanted an average direction of the wind over two readings where the first reading was of 350 degrees and the second was of 10 degrees then the average of the numbers is 180 degrees, whereas if you can note that 350 degrees is equivalent to -10 degrees and so you have two readings at 10 degrees either side of zero degrees leading to a more fitting mean angle of zero degrees. To calculate the mean angle of several angles:
(Note that, since the mean is the sum divided by the number of numbers, and division by a positive real number does not affect the angle, you can also simply compute the sum for step 2.) You can alternatively use this formula:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Averages/Mean angle step by step in the PicoLisp programming language
Source code in the picolisp programming language
(load "@lib/math.l")
(de meanAngle (Lst)
(*/
(atan2
(sum '((A) (sin (*/ A pi 180.0))) Lst)
(sum '((A) (cos (*/ A pi 180.0))) Lst) )
180.0 pi ) )
(for L '((350.0 10.0) (90.0 180.0 270.0 360.0) (10.0 20.0 30.0))
(prinl
"The mean angle of ["
(glue ", " (mapcar round L '(0 .)))
"] is: " (round (meanAngle L))) )
You may also check:How to resolve the algorithm Julia set step by step in the REXX programming language
You may also check:How to resolve the algorithm 100 doors step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Idiomatically determine all the lowercase and uppercase letters step by step in the 11l programming language
You may also check:How to resolve the algorithm Narcissistic decimal number step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Boyer-Moore string search step by step in the Python programming language