Length units and conversions.
More...
|
function | l_mm (v) |
| Shorthand length conversion for millimeters. More...
|
|
function | l_in (v) |
| Shorthand length conversion for inches. More...
|
|
Length units and conversions.
These functions allow for lengths to be specified with units. Lengths specified with units are independent of (length_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 |
pm | picometer |
nm | nanometer |
um | micrometer |
mm | millimeter |
cm | centimeter |
dm | decimeter |
m | meter |
km | kilometer |
thou, mil | thousandth of an inch |
in | inch |
ft | feet |
yd | yard |
mi | mile |
Length base units example script
include <omdl-base.scad>;
c5 =
length(10, from=
"mil", to=
"in");
c6 =
length(10, from=
"ft", to=
"mm");
function length(v, from=length_unit_default, to=length_unit_base, d=1)
Convert a value from from one units to another with dimensions.
function length_unit_name(u=length_unit_default, d=1, w=false)
Return the name for a length unit identifier with dimension.
length_unit_default
<string> The default units when unspecified.
length_unit_base
<string> The base units for value storage.
length_unit_base=mm script output
ECHO: bu = "millimeter"
ECHO: du = "inch"
ECHO:
ECHO: c1 = 3.175
ECHO: c2 = 3.175
ECHO: c3 = 0.635
ECHO: c4 = 2.83168e+7
ECHO: c5 = 0.01
ECHO: c6 = 3048
length_unit_base=cm script output
ECHO: bu = "centimeter"
ECHO: du = "inch"
ECHO:
ECHO: c1 = 0.3175
ECHO: c2 = 0.3175
ECHO: c3 = 0.0635
ECHO: c4 = 28316.8
ECHO: c5 = 0.01
ECHO: c6 = 3048
length_unit_base=mil script output
ECHO: bu = "thousandth"
ECHO: du = "inch"
ECHO:
ECHO: c1 = 125
ECHO: c2 = 125
ECHO: c3 = 25
ECHO: c4 = 1.728e+12
ECHO: c5 = 0.01
ECHO: c6 = 3048
length_unit_base=in script output
ECHO: bu = "inch"
ECHO: du = "inch"
ECHO:
ECHO: c1 = 0.125
ECHO: c2 = 0.125
ECHO: c3 = 0.025
ECHO: c4 = 1728
ECHO: c5 = 0.01
ECHO: c6 = 3048
Equivalent lengths diagramtop |
---|
|
◆ l_in()
Shorthand length conversion for inches.
- Parameters
-
v | <decimal> The value to convert. |
- Returns
- <decimal> The conversion result.
◆ l_mm()
Shorthand length conversion for millimeters.
- Parameters
-
v | <decimal> The value to convert. |
- Returns
- <decimal> The conversion result.
◆ length()
Convert a value from from one units to another with dimensions.
- Parameters
-
v | <decimal> The value to convert. |
from | <string> The units of the value to be converted. |
to | <string> The units to which the value should be converted. |
d | <integer> The unit dimension. One of [1|2|3]. |
- Returns
- <decimal> The conversion result. Returns undef for identifiers or dimensions that are not defined.
◆ length_inv()
Convert a value from from one units to another with dimensions.
- Parameters
-
v | <decimal> The value to convert. |
from | <string> The units of the value to be converted. |
to | <string> The units to which the value should be converted. |
d | <integer> The unit dimension. One of [1|2|3]. |
- Returns
- <decimal> The conversion result. Returns undef for identifiers or dimensions that are not defined.
◆ length_unit_name()
Return the name for a length unit identifier with dimension.
- Parameters
-
u | <string> A length unit identifier. |
d | <integer> The unit dimension. One of [1|2|3]. |
w | <boolean> true for word and false for symbol format. |
- Returns
- <string> The long name for a length unit identifier with dimension. Returns undef for identifiers or dimensions that are not defined.