omdl  v0.6.1
OpenSCAD Mechanical Design Library
Vector Algebra

Algebraic operations on Euclidean vectors. More...

+ Collaboration diagram for Vector Algebra:

Files

file  math-base.scad
 Include file wrapper of math base primitives.
 

Functions

function distance_pp (p1, p2)
 Compute the distance between two Euclidean points. More...
 
function is_left_ppp (p1, p2, p3)
 Test if a point is left, on, or right of an infinite line in a Euclidean 2d-space. More...
 
function dimension_2to3_v (v)
 Return 3d vector unchanged or add a zeroed third dimension to 2d vector. More...
 
function get_line_dim (l)
 Return the number of dimensions of a Euclidean line (or vector). More...
 
function get_line_tp (l)
 Return the terminal point of a Euclidean line (or vector). More...
 
function get_line_ip (l)
 Return the initial point of a Euclidean line (or vector). More...
 
function get_line2origin (l)
 Shift a Euclidean line (or vector) to the origin. More...
 
function dot_ll (l1, l2)
 Compute the dot product of two lines (or vectors). More...
 
function cross_ll (l1, l2)
 Compute the cross product of two lines (or vectors) in a Euclidean 3d or 2d-space. More...
 
function striple_lll (l1, l2, l3)
 Compute the scalar triple product of three lines (or vectors) in a Euclidean 3d or 2d-space. More...
 
function angle_ll (l1, l2)
 Compute the angle between two lines (or vectors) in a Euclidean 3d or 2d-space. More...
 
function angle_lll (l1, l2, n)
 Compute the angle between two lines (or vectors) in a Euclidean 3d-space. More...
 
function unit_l (l)
 Compute the normalized unit vector of a Euclidean line (or vector). More...
 
function are_coplanar_lll (l1, l2, l3, d=6)
 Test if three lines (or vectors) are coplanar in Euclidean 3d-space. More...
 
function get_pnorm2nv (pn, cw=true)
 Convert a planes' normal specification into a normal vector. More...
 

Detailed Description

Algebraic operations on Euclidean vectors.

See validation results.

Function Documentation

function angle_ll ( l1  ,
l2   
)

Compute the angle between two lines (or vectors) in a Euclidean 3d or 2d-space.

Parameters
l1<line-3d|line-2d> A 3d or 2d line (or vector) 1.
l2<line-3d|line-2d> A 3d or 2d line (or vector) 2.
Returns
<decimal> The angle between the two lines (or vectors) in degrees. Returns undef when lines (or vectors) have different dimensions or when they do not intersect.

See Lines and vectors for argument specification and conventions.

Note
For 3d lines (or vectors), a normal is required to uniquely identify the perpendicular plane and axis of rotation. 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_lll().

+ Here is the caller graph for this function:

function angle_lll ( l1  ,
l2  ,
 
)

Compute the angle between two lines (or vectors) in a Euclidean 3d-space.

Parameters
l1<line-3d> A 3d line (or vector) 1.
l2<line-3d> A 3d line (or vector) 2.
n<line-3d> A 3d normal line (or vector).
Returns
<decimal> The angle between the two lines (or vectors) in degrees. Returns undef when lines (or vectors) have different dimensions or when they do not intersect.

See Lines and vectors for argument specification and conventions.

See also
angle_ll().
function are_coplanar_lll ( l1  ,
l2  ,
l3  ,
= 6 
)

Test if three lines (or vectors) are coplanar in Euclidean 3d-space.

Parameters
l1<line-3d> A 3d line (or vector) 1.
l2<line-3d> A 3d line (or vector) 2.
l3<line-3d> A 3d line (or vector) 3.
d<integer> The number of decimal places to consider.
Returns
<boolean> true when all three lines (or vectors) are coplanar, and false otherwise.

See Lines and vectors for argument specification and conventions. See Wikipedia for more information.

Note
When lines (or vectors) are specified with start and end points, this function tests if they are in a planes parallel to the coplanar.
function cross_ll ( l1  ,
l2   
)

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

Parameters
l1<line-3d|line-2d> A 3d or 2d line (or vector) 1.
l2<line-3d|line-2d> A 3d or 2d line (or vector) 2.
Returns
<decimal|vector-2d> The cross product of l1 with l2. Returns undef when lines (or vectors) have different dimensions.

This function supports the abstraction outlined in Lines and vectors. The built-in operation will be more efficient in situations that do not make use of the aforementioned abstraction.

See Lines and vectors for argument specification and conventions. See Wikipedia cross and determinant for more information.

Note
This function returns the 2x2 determinant for 2d vectors.

+ Here is the caller graph for this function:

function dimension_2to3_v ( )

Return 3d vector unchanged or add a zeroed third dimension to 2d vector.

Parameters
v<vector-3d|vector-2d> A vector.
Returns
<vector-3d> The 3d vector or the 2d vector converted to 3d with its third dimension assigned zero.
Warning
To reduce overhead, this function assumes any vector that is not 3d to be 2d.

+ Here is the caller graph for this function:

function distance_pp ( p1  ,
p2   
)

Compute the distance between two Euclidean points.

Parameters
p1<point> A point coordinate 1.
p2<point> A point coordinate 2.
Returns
<decimal> The distance between the two points. Returns undef when points do not have equal dimensions.

When p2 is not given, it is assumed to be at the origin. This function is similar to norm.

+ Here is the caller graph for this function:

function dot_ll ( l1  ,
l2   
)

Compute the dot product of two lines (or vectors).

Parameters
l1<line> A n-dimensional line (or vector) 1.
l2<line> A n-dimensional line (or vector) 2.
Returns
<decimal> The dot product of l1 with l2. Returns undef when lines (or vectors) have different dimensions.

This function supports the abstraction outlined in Lines and vectors. The built-in operation will be more efficient in situations that do not make use of the aforementioned abstraction.

See Lines and vectors for argument specification and conventions. See Wikipedia for more information.

function get_line2origin ( )

Shift a Euclidean line (or vector) to the origin.

Parameters
l<line> A line (or vector).
Returns
<vector> The line (or vector) shifted to the origin.

See Lines and vectors for argument specification and conventions.

+ Here is the caller graph for this function:

function get_line_dim ( )

Return the number of dimensions of a Euclidean line (or vector).

Parameters
l<line> A line (or vector).
Returns
<integer> The number of dimensions for the line (or vector).

See Lines and vectors for argument specification and conventions.

function get_line_ip ( )

Return the initial point of a Euclidean line (or vector).

Parameters
l<line> A line (or vector).
Returns
<point> The initial point of the line (or vector).

See Lines and vectors for argument specification and conventions.

+ Here is the caller graph for this function:

function get_line_tp ( )

Return the terminal point of a Euclidean line (or vector).

Parameters
l<line> A line (or vector).
Returns
<point> The terminal point of the line (or vector).

See Lines and vectors for argument specification and conventions.

+ Here is the caller graph for this function:

function get_pnorm2nv ( pn  ,
cw  = true 
)

Convert a planes' normal specification into a normal vector.

Parameters
pn<pnorm> A plane normal specification.
cw<boolean> Point ordering. When the plane specified as non-collinear points, this indicates ordering.
Returns
<normal> A vector-3d normal to the plane.

See Planes' normal for argument specification and conventions.

function is_left_ppp ( p1  ,
p2  ,
p3   
)

Test if a point is left, on, or right of an infinite line in a Euclidean 2d-space.

Parameters
p1<point-2d> A 2d point coordinate 1.
p2<point-2d> A 2d point coordinate 2.
p3<point-2d> A 2d point coordinate 3.
Returns
<decimal> (> 0) for p3 left of the line through p1 and p2, (= 0) for p3 on the line, and (< 0) for p3 right of the line.

Function patterned after Dan Sunday, 2012.

function striple_lll ( l1  ,
l2  ,
l3   
)

Compute the scalar triple product of three lines (or vectors) in a Euclidean 3d or 2d-space.

Parameters
l1<line-3d|line-2d> A 3d or 2d line (or vector) 1.
l2<line-3d|line-2d> A 3d or 2d line (or vector) 2.
l3<line-3d|line-2d> A 3d or 2d line (or vector) 3.
Returns
<decimal|vector-2d> The scalar triple product. Returns undef when lines (or vectors) have different dimensions.

[l1, l2, l3] = l1 * (l2 x l3)

See Lines and vectors for argument specification and conventions. See Wikipedia for more information.

Warning
Returns a 2d vector result for 2d vectors. The cross product computes the 2x2 determinant of the vectors (l2 x l3), a scalar value, which is then multiplied by l1.
function unit_l ( )

Compute the normalized unit vector of a Euclidean line (or vector).

Parameters
l<line> A line (or vector).
Returns
<vector> The normalized unit vector.

See Lines and vectors for argument specification and conventions.

+ Here is the caller graph for this function: