omdl  v0.9.5
OpenSCAD Mechanical Design Library
Angle Units

Angle units and conversions. More...

+ Collaboration diagram for Angle Units:

Files

file  angle.scad
 Angle units and conversions.
 

Functions

function angle_unit_name (u=angle_unit_default)
 Return the name of an angle unit identifier. More...
 
function angle (a, from=angle_unit_default, to=angle_unit_base)
 Convert an angle from some units to another. More...
 
function angle_inv (a, from=angle_unit_base, to=angle_unit_default)
 Convert an angle from some units to another. More...
 

Variables

 angle_unit_base = "d"
 <string> The base units for value storage.
 
 angle_unit_default = "d"
 <string> The default units when unspecified.
 

Shorts

function a_deg (a)
 Shorthand angle conversion for degrees. More...
 
function a_rad (a)
 Shorthand angle conversion for radians. More...
 

Detailed Description

Angle units and conversions.

Requires:
include <omdl-base.scad>;

These functions allow for angles to be specified with units. Angles specified with units are independent of (angle_unit_base). There are also unit conversion functions for converting from one unit to another.

The table below enumerates the supported units.

units id description type
r radian decimal
d degree decimal
dms degree, minute, second decimal-list-3

Angle base unit example script

include <omdl-base.scad>;
// get unit names
// absolute angle measurements in base unit.
c1 = angle(pi/6);
c2 = angle(pi/4);
c3 = angle(180, "d");
c4 = angle([30, 15, 50], "dms");
// convert between units.
c5 = angle([30, 15, 50], from="dms", to="r");
c6 = angle(0.528205, to="dms");
// end_include
pi
<decimal> The ratio of a circle's circumference to its diameter.
Definition: constants.scad:198
function angle(a, from=angle_unit_default, to=angle_unit_base)
Convert an angle from some units to another.
angle_unit_default
<string> The default units when unspecified.
Definition: angle.scad:494
function angle_unit_name(u=angle_unit_default)
Return the name of an angle unit identifier.
angle_unit_base
<string> The base units for value storage.
Definition: angle.scad:491

angle_unit_base=r script output

ECHO: bu = "radian"
ECHO: du = "radian"
ECHO:
ECHO: c1 = 0.523599
ECHO: c2 = 0.785398
ECHO: c3 = 3.14159
ECHO: c4 = 0.528205
ECHO: c5 = 0.528205
ECHO: c6 = [30, 15, 50.102]

angle_unit_base=d script output

ECHO: bu = "degree"
ECHO: du = "radian"
ECHO:
ECHO: c1 = 30
ECHO: c2 = 45
ECHO: c3 = 180
ECHO: c4 = 30.2639
ECHO: c5 = 0.528205
ECHO: c6 = [30, 15, 50.102]

angle_unit_base=dms script output

ECHO: bu = "degree, minute, second"
ECHO: du = "radian"
ECHO:
ECHO: c1 = [29, 59, 60]
ECHO: c2 = [45, 0, 0]
ECHO: c3 = [180, 0, 0]
ECHO: c4 = [30, 15, 50]
ECHO: c5 = 0.528205
ECHO: c6 = [30, 15, 50.102]

Function Documentation

◆ a_deg()

function a_deg ( )

Shorthand angle conversion for degrees.

Parameters
a<decimal> The angle to convert.
Returns
<decimal> The conversion result.

◆ a_rad()

function a_rad ( )

Shorthand angle conversion for radians.

Parameters
a<decimal> The angle to convert.
Returns
<decimal> The conversion result.

◆ angle()

function angle ( ,
from  = angle_unit_default,
to  = angle_unit_base 
)

Convert an angle from some units to another.

Parameters
a<decimal | decimal-list-3> An angle to convert.
from<string> The units of the angle to be converted.
to<string> A units to which the angle should be converted.
Returns
<decimal | decimal-list-3> The conversion result. Returns undef for identifiers that are not defined.
+ Here is the caller graph for this function:

◆ angle_inv()

function angle_inv ( ,
from  = angle_unit_base,
to  = angle_unit_default 
)

Convert an angle from some units to another.

Parameters
a<decimal | decimal-list-3> An angle to convert.
from<string> The units of the angle to be converted.
to<string> A units to which the angle should be converted.
Returns
<decimal | decimal-list-3> The conversion result. Returns undef for identifiers that are not defined.

◆ angle_unit_name()

function angle_unit_name ( = angle_unit_default)

Return the name of an angle unit identifier.

Parameters
u<string> An angle unit identifier.
Returns
<string> The units name for the given angle unit identifier. Returns undef for identifiers that are not defined.