How to resolve the algorithm Angles (geometric), normalization and conversion step by step in the Common Lisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Angles (geometric), normalization and conversion step by step in the Common Lisp programming language

Table of Contents

Problem Statement

This task is about the normalization and/or conversion of (geometric) angles using some common scales.

The angular scales that will be used in this task are:

The angular scales used or referenced here:

Or, to put it another way,   for a full circle:

A   mil   is approximately equal to a   milliradian   (which is   1/1000   of a radian). There is another definition of a   mil   which is   1/1000   of a radian   ─── this definition won't be used in this Rosetta Code task.

Turns   are sometimes known or shown as:

Degrees   are sometimes known or shown as:

Gradians   are sometimes known or shown as:

Mils   are sometimes known or shown as:

Radians   are sometimes known or shown as:

In continental Europe, the French term   centigrade   was used for   1/100   of a grad (grade);   this was one reason for the adoption of the term   Celsius   to replace   centigrade   as the name of a temperature scale. Gradians were commonly used in civil engineering. Mils were normally used for artillery   (elevations of the gun barrel for ranging).

Although the definition of the measurement of an angle doesn't support the concept of a negative angle,   it's frequently useful to impose a convention that allows positive and negative angular values to represent orientations and/or rotations in opposite directions relative to some reference.   It is this reason that negative angles will keep their sign and not be normalized to positive angles.

Normalization   (for this Rosetta Code task)   will keep the same sign,   but it will reduce the magnitude to less than a full circle;   in other words, less than 360º. Normalization   shouldn't   change   -45º   to   315º, An angle of   0º,   +0º,   0.000000,   or   -0º   should be shown as   0º.

For the (above) conversions,   use these dozen numbers   (in the order shown):

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Angles (geometric), normalization and conversion step by step in the Common Lisp programming language

Source code in the common programming language

(defun DegToDeg (a) (rem a 360))
(defun GradToGrad (a) (rem a 400))
(defun MilToMil (a) (rem a 6400))
(defun RadToRad (a) (rem a (* 2 pi)))

(defun DegToGrad (a) (GradToGrad (* (/ a 360) 400)))
(defun DegToRad (a) (RadToRad (* (/ a 360) (* 2 pi))))
(defun DegToMil (a) (MilToMil (* (/ a 360) 6400)))

(defun GradToDeg (a) (DegToDeg (* (/ a 400) 360)))
(defun GradToRad (a) (RadToRad (* (/ a 400) (* 2 pi))))
(defun GradToMil (a) (MilToMil (* (/ a 400) 6400)))

(defun MilToDeg (a) (DegToDeg (* (/ a 6400) 360)))
(defun MilToGrad (a) (GradToGrad (* (/ a 6400) 400)))
(defun MilToRad (a) (RadToRad (* (/ a 6400) (* 2 pi))))

(defun RadToDeg (a) (DegToDeg (* (/ a (* 2 pi)) 360)))
(defun RadToGrad (a) (GradToGrad (* (/ a (* 2 pi)) 400)))
(defun RadToMil (a) (MilToMil (* (/ a (* 2 pi)) 6400)))

(defun angles (&rest angles)
    (if (not angles) (setf angles '(-2 -1 0 1 2 6.2831853 16 57.2957795 359 399 6399 1000000)))
    (dolist (a angles)
        (format t "UNIT   ~15@a   ~15@a   ~15@a   ~15@a   ~15@a~%" "VAL*" "DEG" "GRAD" "MIL" "RAD")
        (format t "Deg  | ~15f | ~15f | ~15f | ~15f | ~15f~%" a (DegToDeg a) (DegToGrad a) (DegToMil a) (DegToRad a))
        (format t "Grad | ~15f | ~15f | ~15f | ~15f | ~15f~%" a (GradToDeg a) (GradToGrad a) (GradToMil a) (GradToRad a))
        (format t "Mil  | ~15f | ~15f | ~15f | ~15f | ~15f~%" a (MilToDeg a) (MilToGrad a) (MilToMil a) (MilToRad a))
        (format t "Rad  | ~15f | ~15f | ~15f | ~15f | ~15f~%~%" a (RadToDeg a) (RadToGrad a) (RadToMil a) (RadToRad a))))


  

You may also check:How to resolve the algorithm Penta-power prime seeds step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Ludic numbers step by step in the Elixir programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the Lingo programming language
You may also check:How to resolve the algorithm Input loop step by step in the C programming language