omdl  v0.5
OpenSCAD Mechanical Design Library
Length

Length units and conversions. More...

+ Collaboration diagram for Length:

Files

file  units_length.scad
 Length units and conversions.
 

Functions

function unit_length_name (units=base_unit_length, d=1, w=false)
 Return the name of the given unit identifier with dimension. More...
 
function convert_length (value, from=base_unit_length, to=base_unit_length, d=1)
 Convert the value from from units to to units with dimensions. More...
 

Variables

 base_unit_length = "mm"
 <string> Base unit for length measurements.
 

Detailed Description

Length units and conversions.

These functions allow for lengths to be specified with units. Lengths specified with units are independent of (base_unit_length). There are also unit conversion functions for converting from one unit to another.

The table below enumerates the supported unit identifiers and their descriptions.

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

Example

include <units_length.scad>;
// get base unit name
// absolute length measurements in base unit.
c1 = convert_length(1/8, "in");
c2 = convert_length(3.175, "mm");
c3 = convert_length(25, "mil");
c4 = convert_length(1, "ft", d=3);
// convert between units.
c5 = convert_length(10, from="mil", to="in");
c6 = convert_length(10, from="ft", to="mm");

Result (base_unit_length = mm):

ECHO: un = "millimeter"
ECHO: c1 = 3.175
ECHO: c2 = 3.175
ECHO: c3 = 0.635
ECHO: c4 = 2.83168e+07
ECHO: c5 = 0.01
ECHO: c6 = 3048

Result (base_unit_length = cm):

ECHO: un = "centimeter"
ECHO: c1 = 0.3175
ECHO: c2 = 0.3175
ECHO: c3 = 0.0635
ECHO: c4 = 28316.8
ECHO: c5 = 0.01
ECHO: c6 = 3048

Result (base_unit_length = mil):

ECHO: un = "thousandth"
ECHO: c1 = 125
ECHO: c2 = 125
ECHO: c3 = 25
ECHO: c4 = 1.728e+12
ECHO: c5 = 0.01
ECHO: c6 = 3048

Result (base_unit_length = in):

ECHO: un = "inch"
ECHO: c1 = 0.125
ECHO: c2 = 0.125
ECHO: c3 = 0.025
ECHO: c4 = 1728
ECHO: c5 = 0.01
ECHO: c6 = 3048

Example (equivalent lengths)

units_length_dim_qvga_top.png
Unit Lengths

Function Documentation

function convert_length ( value  ,
from  = base_unit_length,
to  = base_unit_length,
= 1 
)

Convert the value from from units to to units with dimensions.

Parameters
value<decimal> A value to convert.
from<string> The units of the value to be converted.
to<string> A units to which the value should be converted.
d<decimal> The dimension set to one of [1|2|3].
Returns
<decimal> The conversion result. Returns 'undef' for identifiers or dimensions that are not defined.
function unit_length_name ( units  = base_unit_length,
= 1,
= false 
)

Return the name of the given unit identifier with dimension.

Parameters
w<boolean> true: use word format, false: use symbol format.
units<string> A length unit identifier.
d<decimal> A dimension set to one of [1|2|3].
Returns
<string> The units name for the given length unit identifier with is specified dimension. Returns 'undef' for identifiers or dimensions that are not defined.