omdl  v0.9.5
OpenSCAD Mechanical Design Library
Euclidean space data types

For geometric specifications and geometric algebra, omdl adopts 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

A vector has 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. Although a line can be specified in one dimension, most library functions operate on two and/or three dimensional lines. 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 vector from the origin to 'p2'
2 [p2] a vector from the origin to 'p2'
3 [p1, p2] a line from 'p1' to 'p2'

The functions is_point(), is_vector(), is_line(), line_dim(), line_tp(), line_ip(), vol_to_point(), and vol_to_origin(), are available for type identification and convertion.

Example

// points
p1 = [a,b,c]
p2 = [d,e,f]
// vectors
v1 = p2 = [d,e,f]
v2 = [p2] = [[d,e,f]]
// lines
v3 = [p1, p2] = [[a,b,c], [d,e,f]]
v1 == v2
v1 == v2 == v3, iff p1 == origin3d
origin3d
<point-3d> The origin point coordinate in 3-dimensional Euclidean space.
Definition: constants.scad:425

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 functions is_plane() and plane_to_normal() are available for type identification and convertion.

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
function cross_ll(l1, l2)
Compute the cross product of two lines or vectors in a 3d or 2d-space.
function mean(v)
Compute the mean/average of a list of numbers.