omdl  v0.6.1
OpenSCAD Mechanical Design Library
Data types

Built-in

omdl assumes a value is either a number, a boolean, a string, a list, a range, or the undefined value. What is called a vector in the OpenSCAD types documentation is refereed to as a list here in order to distinguish between sequential lists of values and Euclidean vectors.

type description
value any valid OpenSCAD storable datum
number an arithmetic value
boolean a binary logic value (true or false)
string a sequential list of of character values
list a sequential list of arbitrary values
range an arithmetic sequence
undef the undefined value

Special numerical values

value description
nan a numerical value which is not a number
inf a numerical value which is infinite

Additional conventions

When a list has an expected number of elements 'n', the count is appended following a '-'. When there is a range of expected elements, the lower and upper bounds are separated by a ':' and appended (order of bounds may be reversed). When the elements values are of an expected type, that type is prepended. Combinations are used as needed as in the following table:

name description
list-n a list of of n elements
list-l:u a list of l to u elements
type-list a list of elements with an expected type
type-list-n a list of n elements with an expected type

Distinctions

omdl make the following distinctions on variable types.

name description
scalar a single non-iterable value
iterable a multi-part sequence of values
empty an iterable value with zero elements
even an even numerical value
odd an odd numerical value

General

From the fixed built-in set of data types, omdl adds the following general type specifications and conventions.

name description
bit a binary numerical value (0 or 1)
integer a positive, negative, or zero whole number
decimal integer numbers with a fractional part
index a list index sequence
datastruct a defined data structure
data an arbitrary data structure

Index sequence

The data type index refers to a specified sequence of list element indexes. A list index sequence may be specified in one of the following forms.

value / form description
true All index positions of the list [0:size-1]
false No index positions
"all" All index positions of the list [0:size-1]
"none" No index positions
"rands" Random index selection of the list [0:size-1]
"even" The even index of the list [0:size-1]
"odd" The odd index of the list [0:size-1]
<integer> The single position given by an <integer>
<range> The range of positions given by a <range>
<integer-list> The list of positions give in <integer-list>

The function get_index() can be used to convert a value of this data type into a sequence of list element indexes.

Example

// list
l1 = [a,b,c,d,e,f]
// index sequence
get_index(l1) = [0,1,2,3,4,5]
get_index(l1, "rands") = [0,2,5]

Geometric

For geometric specifications and geometric algebra, omdl adds the following type specifications and conventions.

name description
point a list of numbers to identify a location in space
vector a direction and magnitude in space
line a start and end point in space (line wiki)
normal a vector that is perpendicular to a given object
pnorm a vector that is perpendicular to a plane
plane a flat 2d infinite surface (plane wiki)
coords a list of points in space
matrix a rectangular array of values

When a particular dimension is expected, the dimensional expectation is appended to the end of the name after a '-' dash as in the following table.

name description
point-Nd a point in an 'N' dimensional space
vector-Nd a vector in an 'N' dimensional space
line-Nd a line in an 'N' dimensional space
coords-Nd a coordinate list in an 'N' dimensional space
matrix-MxN a 'M' by 'N' matrix of values

Lines and vectors

The data type line refers to a convention for specifying a line or a vector. A vector is a direction and magnitude in space. A line, too, has direction and magnitude, but also has location, as it starts at one point in space and ends at another. Operators in omdl make use of a common convention for specifying Euclidean vectors and straight lines as summarized in the following table:

Given two points 'p1' and 'p2', in space:

no. form description
1 p2 a line or vector from the origin to 'p2'
2 [p2] a line or vector from the origin to 'p2'
3 [p1, p2] line or vector from 'p1' to 'p2'

The functions get_line_dim(), get_line_tp(), get_line_ip(), and get_line2origin(), are available to identify the dimension of and convert a line into a vector or point.

Example

// points
p1 = [a,b,c]
p2 = [d,e,f]
// lines and vectors
v1 = p2 = [d,e,f]
v2 = [p2] = [[d,e,f]]
v3 = [p1, p2] = [[a,b,c], [d,e,f]]
v1 == v2
v1 == v2 == v3, iff p1 == origin3d

Planes

Operators in omdl use a common convention for specifying planes. A plane is identified by a point on its surface together with its normal vector specified by pnorm, which is discussed in the following section. A list with a point and normal together specify the plane as follows:

name form
plane [point, pnorm]

Planes' normal

The data type pnorm refers to a convention for specifying a direction vector that is perpendicular to a plane. Given three points 'p1', 'p2', 'p3', and three vectors 'v1', 'v2', 'vn', the planes' normal can be specified in any of the following forms:

no. form description
1 vn the predetermined normal vector to the plane
2 [vn] the predetermined normal vector to the plane
3 [v1, v2] two distinct but intersecting vectors
4 [p1, p2, p3] three (or more) non-collinear coplanar points

The function get_pnorm2nv() can be used to convert a value of this data type into a normal vector.

Example

// points
p1 = [a,b,c];
p2 = [d,e,f];
p3 = [g,h,i];
// lines and vectors
v1 = [p1, p2] = [[a,b,c], [d,e,f]]
v2 = [p1, p3] = [[a,b,c], [g,h,i]]
vn = cross_ll(v1, v2)
// planes' normal
n1 = vn = cross_ll(v1, v2)
n2 = [vn] = cross_ll(v1, v2)
n3 = [v1, v2] = [[[a,b,c],[d,e,f]], [[a,b,c],[g,h,i]]]
n4 = [p1, p2, p3] = [[a,b,c], [d,e,f], [g,h,i]]
n1 || n2 || n3 || n4
// planes
pn1 = [p1, n1]
pn2 = [p2, n2]
pn3 = [p3, n3]
pn4 = [n4[0], n4]
pn5 = [mean(n4), n4]
pn1 == pn4