omdl  v1.0
OpenSCAD Mechanical Design Library
Angle Units

Angle units and conversions. More...

+ Collaboration diagram for Angle Units:

Files

file  angle.scad
 Angle units and conversions.
 

Shorts

Convenience wrappers around angle that fix the from unit to a named unit. The to parameter defaults to angle_unit_base and may be overridden when a non-default target unit is needed. Use angle directly when the source unit is also non-default.

function a_deg (a, to=angle_unit_base)
 Shorthand angle conversion for degrees. More...
 
function a_rad (a, to=angle_unit_base)
 Shorthand angle conversion for radians. More...
 

Functions and/or Modules

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 value from one unit to another. More...
 
function angle_inv (a, from=angle_unit_base, to=angle_unit_default)
 Convert an angle value from one unit to another (direction-swapped defaults). More...
 

Variables

 angle_unit_base = "d"
 
 angle_unit_default = "d"
 

Usage Details

Angle units and conversions.

Validation Summary

filegroupscriptresultsno testskippedpassedfailedwarning
units/angle.scadAngle UnitsScriptResults30000

No Failures

See complete validation results.

Requires:
include <omdl-base.scad>;

Conventions

Parameter naming

Return values

DMS format

Global configuration

Unit identifiers

Shorthand functions

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 value from one unit to another.
angle_unit_default
Definition: angle.scad:747
function angle_unit_name(u=angle_unit_default)
Return the name of an angle unit identifier.
angle_unit_base
Definition: angle.scad:741

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 and/or Module Documentation

◆ 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.

◆ angle()

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

Convert an angle value from one unit to another.

Parameters
a<decimal | decimal-list-3> The angle to convert.
from<string> The units of the angle to be converted. Defaults to angle_unit_default.
to<string> The units to which the angle should be converted. Defaults to angle_unit_base. Conversion to "d" is short-circuited: the intermediate d to step is skipped.
Returns
<decimal | decimal-list-3> The conversion result. Return type is a scalar for "r" or "d", and a 3-element list for "dms". 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 value from one unit to another (direction-swapped defaults).

Parameters
a<decimal | decimal-list-3> The angle to convert.
from<string> The units of the angle to be converted. Defaults to angle_unit_base.
to<string> The units to which the angle should be converted. Defaults to angle_unit_default.
Returns
<decimal | decimal-list-3> The conversion result. Return type is a scalar for "r" or "d", and a 3-element list for "dms". Returns undef for identifiers that are not defined.
Note
This is a convenience alias for angle with from and to defaults swapped. It is useful when the natural direction of a design is from the base unit back to a display or input unit.

◆ a_deg()

function a_deg ( ,
to  = angle_unit_base 
)

Shorthand angle conversion for degrees.

Parameters
a<decimal> The angle to convert.
to<string> The units to which the angle should be converted. Defaults to angle_unit_base.
Returns
<decimal> The conversion result.

◆ a_rad()

function a_rad ( ,
to  = angle_unit_base 
)

Shorthand angle conversion for radians.

Parameters
a<decimal> The angle to convert.
to<string> The units to which the angle should be converted. Defaults to angle_unit_base.
Returns
<decimal> The conversion result.

Variable Documentation

◆ angle_unit_base

angle_unit_base = "d"

<string> The base units for value storage.

Note
This variable is intended to be overridden at the top of a design file or in a child scope. All angle functions that omit the to parameter will convert to this unit.

Definition at line 741 of file angle.scad.

◆ angle_unit_default

angle_unit_default = "d"

<string> The default units when unspecified.

Note
This variable is intended to be overridden at the top of a design file or in a child scope. All angle functions that omit the from or u parameter will assume this unit.

Definition at line 747 of file angle.scad.