How to resolve the algorithm Angles (geometric), normalization and conversion step by step in the Wren 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 Wren 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 Wren programming language

Source code in the wren programming language

import "./fmt" for Fmt

var d2d = Fn.new { |d| d % 360 }
var g2g = Fn.new { |g| g % 400 }
var m2m = Fn.new { |m| m % 6400 }
var r2r = Fn.new { |r| r % (2*Num.pi) }
var d2g = Fn.new { |d| d2d.call(d) * 400 / 360 }
var d2m = Fn.new { |d| d2d.call(d) * 6400 / 360 }
var d2r = Fn.new { |d| d2d.call(d) * Num.pi / 180 }
var g2d = Fn.new { |g| g2g.call(g) * 360 / 400 }
var g2m = Fn.new { |g| g2g.call(g) * 6400 / 400 }
var g2r = Fn.new { |g| g2g.call(g) * Num.pi / 200 }
var m2d = Fn.new { |m| m2m.call(m) * 360 / 6400 }
var m2g = Fn.new { |m| m2m.call(m) * 400 / 6400 }
var m2r = Fn.new { |m| m2m.call(m) * Num.pi / 3200 }
var r2d = Fn.new { |r| r2r.call(r) * 180 / Num.pi }
var r2g = Fn.new { |r| r2r.call(r) * 200 / Num.pi }
var r2m = Fn.new { |r| r2r.call(r) * 3200 / Num.pi }

var f1 = "$15m $15m $15m $15m $15m"
var f2 = "$15.7g $15.7g $15.7g $15.7g $15.7g"
var angles = [-2, -1, 0, 1, 2, 6.2831853, 16, 57.2957795, 359, 399, 6399, 1000000]
Fmt.print(f1, "degrees", "normalized degs", "gradians", "mils", "radians")
for (a in angles) {
    Fmt.print(f2, a, d2d.call(a), d2g.call(a), d2m.call(a), d2r.call(a))
}
f1 = "\n" + f1
Fmt.print(f1, "gradians", "normalized grds", "degrees", "mils", "radians")
for (a in angles) {
    Fmt.print(f2, a, g2g.call(a), g2d.call(a), g2m.call(a), g2r.call(a))
}
Fmt.print(f1, "mils", "normalized mils", "degrees", "gradians", "radians")
for (a in angles) {
    Fmt.print(f2, a, m2m.call(a), m2d.call(a), m2g.call(a), m2r.call(a))
}
Fmt.print(f1, "radians", "normalized rads", "degrees", "gradians", "mils")
for (a in angles) {
    Fmt.print(f2, a, r2r.call(a), r2d.call(a), r2g.call(a), r2m.call(a))
}


  

You may also check:How to resolve the algorithm Generator/Exponential step by step in the Nim programming language
You may also check:How to resolve the algorithm Equilibrium index step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Get system command output step by step in the REXX programming language
You may also check:How to resolve the algorithm Long year step by step in the TypeScript programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Bracmat programming language