![]() |
omdl
v1.0
OpenSCAD Mechanical Design Library
|
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 | |
| 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" | |
Angle units and conversions.
| file | group | script | results | no test | skipped | passed | failed | warning |
|---|---|---|---|---|---|---|---|---|
| units/angle.scad | Angle Units | Script | Results | 3 | 0 | 0 | 0 | 0 |
See complete validation results.
| Requires: |
|---|
| include <omdl-base.scad>; |
Parameter naming
a is the angle value to convert. It has no default and must always be supplied by the caller. It may be a scalar for "r" or "d", or a 3-element list for "dms"; the required type depends on the source unit.from identifies the source unit; defaults to angle_unit_default.to identifies the target unit; defaults to angle_unit_base.u is a unit-identifier string used in name-lookup functions; defaults to angle_unit_default.Return values
"r" or "d", and a 3-element list for "dms".DMS format
"dms" (degree, minute, second) type is represented as a 3-element list [degrees, minutes, seconds].degrees component. The minutes and seconds components are always non-negative. For example, −30°15′20″ is encoded as [-30, 15, 20]."dms" value with mixed signs (e.g. [-30,-15,0]) is not supported and produces undefined results.Global configuration
"d" and is intended to be overridden at the top of a design file or within a child scope before any angle function is called.from or u is not specified. It also defaults to "d".Unit identifiers
"r", "d", "dms").Shorthand functions
a_deg() and a_rad() helpers are convenience wrappers that fix from to their named unit. The to parameter defaults to angle_unit_base and may be overridden when a non-default target unit is needed.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
angle_unit_base=r script output
angle_unit_base=d script output
angle_unit_base=dms script output
| function angle_unit_name | ( | u | = angle_unit_default | ) |
Return the name of an angle unit identifier.
| u | <string> An angle unit identifier. |
| function angle | ( | a | , |
| from | = angle_unit_default, |
||
| to | = angle_unit_base |
||
| ) |
Convert an angle value from one unit to another.
| 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. |
"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:| function angle_inv | ( | a | , |
| from | = angle_unit_base, |
||
| to | = angle_unit_default |
||
| ) |
Convert an angle value from one unit to another (direction-swapped defaults).
| 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. |
"r" or "d", and a 3-element list for "dms". Returns undef for identifiers that are not defined.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. | function a_deg | ( | a | , |
| to | = angle_unit_base |
||
| ) |
Shorthand angle conversion for degrees.
| a | <decimal> The angle to convert. |
| to | <string> The units to which the angle should be converted. Defaults to angle_unit_base. |
| function a_rad | ( | a | , |
| to | = angle_unit_base |
||
| ) |
Shorthand angle conversion for radians.
| a | <decimal> The angle to convert. |
| to | <string> The units to which the angle should be converted. Defaults to angle_unit_base. |
| angle_unit_base = "d" |
<string> The base units for value storage.
to parameter will convert to this unit. Definition at line 741 of file angle.scad.
| angle_unit_default = "d" |
<string> The default units when unspecified.
from or u parameter will assume this unit. Definition at line 747 of file angle.scad.