omdl  v0.6.1
OpenSCAD Mechanical Design Library
Angles

Angle units and conversions. More...

+ Collaboration diagram for Angles:

Files

file  units_angle.scad
 Angle units and conversions.
 

Functions

function unit_angle_name (u=base_unit_angle)
 Return the name of an angle unit identifier. More...
 
function convert_angle (a, from=base_unit_angle, to=base_unit_angle)
 Convert an angle from some units to another. More...
 

Variables

 base_unit_angle = "d"
 <string> The base units for angle measurements.
 

Detailed Description

Angle units and conversions.

These functions allow for angles to be specified with units. Angles specified with units are independent of (base_unit_angle). 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

Example

include <units/units_angle.scad>;
// get base unit name
// absolute angle measurements in base unit.
c1 = convert_angle(pi/6, "r");
c2 = convert_angle(pi/4, "r");
c3 = convert_angle(180, "d");
c4 = convert_angle([30, 15, 50], "dms");
// convert between units.
c5 = convert_angle([30, 15, 50], from="dms", to="r");
c6 = convert_angle(0.528205, from="r", to="dms");

Result (base_angle_length = r):

ECHO: un = "radian"
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]

Result (base_angle_length = d):

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

Result (base_angle_length = dms):

ECHO: un = "degree, minute, second"
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

function convert_angle ( ,
from  = base_unit_angle,
to  = base_unit_angle 
)

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.
function unit_angle_name ( = base_unit_angle)

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.