omdl  v0.5
OpenSCAD Mechanical Design Library
Point, Vector and Plane

Point, vector, and plane computations. More...

+ Collaboration diagram for Point, Vector and Plane:

Files

file  math.scad
 Mathematical functions.
 

Functions

function distance_pp (p1, p2)
 Compute the distance between two points in a Euclidean 1, 2, or 3D-space. More...
 
function dot_vv (v1t, v2t, v1i, v2i)
 Compute the dot product of two vectors. More...
 
function cross_vv (v1t, v2t, v1i, v2i)
 Compute the cross product of two vectors in a Euclidean 3D-space (2D). More...
 
function striple_vvv (v1t, v2t, v3t, v1i, v2i, v3i)
 Compute scalar triple product of two vectors in a Euclidean 3D-space. More...
 
function angle_vv (v1t, v2t, v1i, v2i)
 Compute the angle between two vectors in a Euclidean 2 or 3D-space. More...
 
function angle_vvn (v1t, v2t, nvt, v1i, v2i, nvi)
 Compute the angle between two vectors in a Euclidean 3D-space. More...
 
function unit_v (vt, vi)
 Compute the normalized unit vector for a 1, 2, or 3 term vector. More...
 
function are_coplanar_vvv (v1t, v2t, v3t, v1i, v2i, v3i)
 Test if three vectors are coplanar in Euclidean 3D-space. More...
 

Detailed Description

Point, vector, and plane computations.

See validation results.

Function Documentation

function angle_vv ( v1t  ,
v2t  ,
v1i  ,
v2i   
)

Compute the angle between two vectors in a Euclidean 2 or 3D-space.

Parameters
v1t<vector> Vector 1 head. A 2 or 3-tuple of coordinates.
v2t<vector> Vector 2 head. A 2 or 3-tuple of coordinates.
v1i<vector> Vector 1 tail. A 2 or 3-tuple of coordinates.
v2i<vector> Vector 2 tail. A 2 or 3-tuple of coordinates.
Returns
<decimal> The angle between the two vectors in degrees. Returns 'undef' when vector coordinates do not have same number of terms or when the vectors do not intersect.

Each vector may be specified by both its head and tail coordinates. When specified by head coordinate only, the tail is assumed to be at origin.

Note
For 3D vectors, a normal vector is required to uniquely identify the perpendicular plane and axis of rotation for the two vectors. This function calculates the positive angle, and the plane and axis of rotation will be that which fits this assumed positive angle.
See also
angle_vvn().
function angle_vvn ( v1t  ,
v2t  ,
nvt  ,
v1i  ,
v2i  ,
nvi   
)

Compute the angle between two vectors in a Euclidean 3D-space.

Parameters
v1t<vector> Vector 1 head. A 3-tuple of coordinates.
v2t<vector> Vector 2 head. A 3-tuple of coordinates.
nvt<vector> Normal vector head. A 3-tuple of coordinates.
v1i<vector> Vector 1 tail. A 3-tuple of coordinates.
v2i<vector> Vector 2 tail. A 3-tuple of coordinates.
nvi<vector> Normal vector tail. A 3-tuple of coordinates.
Returns
<decimal> The angle between the two vectors in degrees. Returns 'undef' when vector coordinates do not have same number of terms or when the vectors do not intersect.

Each vector may be specified by both its head and tail coordinates. When specified by head coordinate only, the tail is assumed to be at origin.

See also
angle_vv().
function are_coplanar_vvv ( v1t  ,
v2t  ,
v3t  ,
v1i  ,
v2i  ,
v3i   
)

Test if three vectors are coplanar in Euclidean 3D-space.

Parameters
v1t<vector> Vector 1 head. A 3-tuple of coordinates.
v2t<vector> Vector 2 head. A 3-tuple of coordinates.
v3t<vector> Vector 3 head. A 3-tuple of coordinates.
v1i<vector> Vector 1 tail. A 3-tuple of coordinates.
v2i<vector> Vector 2 tail. A 3-tuple of coordinates.
v3i<vector> Vector 3 tail. A 3-tuple of coordinates.
Returns
<boolean> true when all three vectors are coplanar, and false otherwise.

Each vector may be specified by both its head and tail coordinates. When specified by head coordinate only, the tail is assumed to be at origin.

See Wikipedia for more information.

Note
Coplanar vectors must all be within the same plane. However, this function can test if vectors are in a plane that is parallel to a coplanar plane by using non-zero vector tails.
function cross_vv ( v1t  ,
v2t  ,
v1i  ,
v2i   
)

Compute the cross product of two vectors in a Euclidean 3D-space (2D).

Parameters
v1t<vector> Vector 1 head. A 2 or 3-tuple of coordinates.
v2t<vector> Vector 2 head. A 2 or 3-tuple of coordinates.
v1i<vector> Vector 1 tail. A 2 or 3-tuple of coordinates.
v2i<vector> Vector 2 tail. A 2 or 3-tuple of coordinates.
Returns
<decimal> The cross product of the two vectors. Returns 'undef' when vector coordinates do not have same number of terms, n.

Each vector may be specified by both its head and tail coordinates. When specified by head coordinate only, the tail is assumed to be at origin.

See Wikipedia cross and determinant for more information.

Note
Although the cross product of two vectors is defined only in 3D space, this function will return the 2x2 determinant for a 2D vector.
function distance_pp ( p1  ,
p2   
)

Compute the distance between two points in a Euclidean 1, 2, or 3D-space.

Parameters
p1<vector> A 1, 2, or 3-tuple of coordinates.
p2<vector> A 1, 2, or 3-tuple of coordinates.
Returns
<decimal> The distance between the two points. Returns 'undef' when x and y do not have same number of terms or for n-tuple where n>3.

When p2 is not given, it is assumed to be at the origin.

function dot_vv ( v1t  ,
v2t  ,
v1i  ,
v2i   
)

Compute the dot product of two vectors.

Parameters
v1t<vector> Vector 1 head. An n-tuple of coordinates.
v2t<vector> Vector 2 head. An n-tuple of coordinates.
v1i<vector> Vector 1 tail. An n-tuple of coordinates.
v2i<vector> Vector 2 tail. An n-tuple of coordinates.
Returns
<decimal> The dot product of the two vectors. Returns 'undef' when vector coordinates do not have same number of terms, n.

Each vector may be specified by both its head and tail coordinates. When specified by head coordinate only, the tail is assumed to be at origin.

See Wikipedia for more information.

function striple_vvv ( v1t  ,
v2t  ,
v3t  ,
v1i  ,
v2i  ,
v3i   
)

Compute scalar triple product of two vectors in a Euclidean 3D-space.

Parameters
v1t<vector> Vector 1 head. A 2 or 3-tuple of coordinates.
v2t<vector> Vector 2 head. A 2 or 3-tuple of coordinates.
v3t<vector> Vector 3 head. A 2 or 3-tuple of coordinates.
v1i<vector> Vector 1 tail. A 2 or 3-tuple of coordinates.
v2i<vector> Vector 2 tail. A 2 or 3-tuple of coordinates.
v3i<vector> Vector 3 tail. A 2 or 3-tuple of coordinates.
Returns
<decimal> The scalar triple product of the three vectors. Returns 'undef' when vector coordinates do not have same number of terms, n.

Each vector may be specified by both its head and tail coordinates. When specified by head coordinate only, the tail is assumed to be at origin.

[v1, v2, v3] = v1 * (v2 x v3)

See Wikipedia for more information.

Warning
For 2D vectors, this function produces a 2D non-scalar vector result. The cross produce function computes the 2x2 determinant of the 2D vectors (v2 x v3), which is a scalar value, and this value is multiplied by v1, which results in a 2D vector.
function unit_v ( vt  ,
vi   
)

Compute the normalized unit vector for a 1, 2, or 3 term vector.

Parameters
vt<vector> Vector head. A 1, 2, or 3-tuple of coordinates.
vi<vector> Vector tail. A 1, 2, or 3-tuple of coordinates.
Returns
<vector> The vector normalized to its unit-vector. Returns 'undef' when vector coordinates do not have same number of terms or for n-tuple where n>3.

The vector may be specified by both its head and tail coordinates. When specified by head coordinate only, the tail is assumed to be at origin.