omdl
v0.6.1
OpenSCAD Mechanical Design Library
|
Polygon and polyhedron mathematical functions. More...
Files | |
file | math_polytope.scad |
Polygon and polyhedron mathematical functions. | |
Functions | |
function | polytope_faces2edges (f) |
List the edge coordinate index pairs of a polytope. More... | |
function | polytope_limits (c, f, a, d=[0:2], s=true) |
Determine the bounding limits of a polytope. More... | |
function | polytope_bbox_pf (c, f, a) |
Generate a bounding box polytope for another polytope in 3d or 2d. More... | |
function | polytope_line (c, f, e, i, l, r=false) |
Get a line from an edge or any two vetices of a polytope. More... | |
function | polytope_vertex_av (f, i) |
List the adjacent vertices for a given polytope vertex. More... | |
function | polytope_vertex_af (f, i) |
List the adjacent face indexes for a polytope vertex. More... | |
function | polytope_edge_af (f, e, i) |
List the adjacent face indexes for a polytope edge. More... | |
function | polytope_vertex_n (c, f, i) |
Get a normal vector for a polytope vertex. More... | |
function | polytope_edge_n (c, f, e, i) |
Get a normal vector for a polytope edge. More... | |
function | polytope_face_n (c, f, i, l, cw=true) |
Get the normal vector of a polytope face. More... | |
function | polytope_face_m (c, f, i, l) |
Get the mean coordinate of all vertices of a polytope face. More... | |
function | polytope_face_mn (c, f, i, l, cw=true) |
Get the mean coordinate and normal vector of a polytope face. More... | |
function | polytope_plane (c, f, i, l, cw=true) |
Get a plane for a polytope face. More... | |
function | polytope_face_vcounts (f) |
List the vertex counts for all polytope faces. More... | |
function | polytope_face_angles (c, f) |
List the angles between all adjacent faces of a polyhedron. More... | |
function | polytope_edge_lengths (c, e) |
List the edge lengths of a polytope. More... | |
function | polytope_edge_angles (c, f) |
List the adjacent edge angles for each polytope vertex. More... | |
function | polytope_faces_are_regular (c, f, e, d=6) |
Test if the faces of a polytope are all regular. More... | |
function | polytope_triangulate_ft (f) |
Triangulate the faces of a convex polytope using fan triangulation. More... | |
function | polygon2d_perimeter (c, p) |
Calculate the perimeter length of a polygon in 2d. More... | |
function | polygon2d_area (c, p, s=false) |
Compute the signed area of a polygon in a Euclidean 2d-space. More... | |
function | polygon3d_area (c, p, n) |
Compute the area of a polygon in a Euclidean 3d-space. More... | |
function | polygon2d_centroid (c, p) |
Compute the center of mass of a polygon in a Euclidean 2d-space. More... | |
function | polygon2d_is_cw (c, p) |
Test the vertex ordering of a polygon in a Euclidean 2d-space. More... | |
function | polygon2d_is_convex (c, p) |
Test the convexity of a polygon in a Euclidean 2d-space. More... | |
function | polygon2d_winding (c, p, t) |
Compute the winding number of a polygon about a point in a Euclidean 2d-space. More... | |
function | polygon2d_is_pip_wn (c, p, t) |
Test if a point is inside a polygon in a Euclidean 2d-space using winding number. More... | |
function | polygon2d_is_pip_as (c, p, t) |
Test if a point is inside a polygon in a Euclidean 2d-space using angle summation. More... | |
function | polyhedron_area (c, f) |
Compute the surface area of a polyhedron in a Euclidean 3d-space. More... | |
function | polyhedron_volume_tf (c, f) |
Compute the volume of a triangulated polyhedron in a Euclidean 3d-space. More... | |
function | polyhedron_centroid_tf (c, f) |
Compute the center of mass of a triangulated polyhedron in a Euclidean 3d-space. More... | |
function | linear_extrude_pp2pf (c, p, h=1, centroid=false, center=false) |
Convert a polygon to a polyhedron by adding a height dimension. More... | |
Polygon and polyhedron mathematical functions.
function linear_extrude_pp2pf | ( | c | , |
p | , | ||
h | = 1 , |
||
centroid | = false , |
||
center | = false |
||
) |
Convert a polygon to a polyhedron by adding a height dimension.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
h | <decimal> The polyhedron height. |
centroid | <boolean> Center polygon centroid at z-axis. |
center | <boolean> Center polyhedron height about xy-plane. |
[points, faces]
, where points
are <coords-3d> and faces
are a <integer-list-list>, that define the bounding box of the given polyhedron.p
is not given, the listed order of the coordinates c
establishes the path. function polygon2d_area | ( | c | , |
p | , | ||
s | = false |
||
) |
Compute the signed area of a polygon in a Euclidean 2d-space.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
s | <boolean> Return the vertex ordering sign. |
See Wikipedia for more information.
p
is not given, the listed order of the coordinates c
establishes the path. function polygon2d_centroid | ( | c | , |
p | |||
) |
Compute the center of mass of a polygon in a Euclidean 2d-space.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
See Wikipedia for more information.
p
is not given, the listed order of the coordinates c
establishes the path. function polygon2d_is_convex | ( | c | , |
p | |||
) |
Test the convexity of a polygon in a Euclidean 2d-space.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
p
is not given, the listed order of the coordinates c
establishes the path. function polygon2d_is_cw | ( | c | , |
p | |||
) |
Test the vertex ordering of a polygon in a Euclidean 2d-space.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
p
is not given, the listed order of the coordinates c
establishes the path. function polygon2d_is_pip_as | ( | c | , |
p | , | ||
t | |||
) |
Test if a point is inside a polygon in a Euclidean 2d-space using angle summation.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
t | <point-2d> A test point coordinate [x, y]. |
See Wikipedia for more information.
p
is not given, the listed order of the coordinates c
establishes the path. function polygon2d_is_pip_wn | ( | c | , |
p | , | ||
t | |||
) |
Test if a point is inside a polygon in a Euclidean 2d-space using winding number.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
t | <point-2d> A test point coordinate [x, y]. |
p
is not given, the listed order of the coordinates c
establishes the path.function polygon2d_perimeter | ( | c | , |
p | |||
) |
Calculate the perimeter length of a polygon in 2d.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
p
is not given, the listed order of the coordinates c
establishes the path. function polygon2d_winding | ( | c | , |
p | , | ||
t | |||
) |
Compute the winding number of a polygon about a point in a Euclidean 2d-space.
c | <coords-2d> A list of 2d cartesian coordinates [[x, y], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
t | <point-2d> A test point coordinate [x, y]. |
Computes the winding number, the total number of counterclockwise turns that the polygon paths makes around the test point in a Euclidean 2d-space. Will be 0 iff the point is outside of the polygon. Function patterned after Dan Sunday, 2012.
Copyright 2000 softSurfer, 2012 Dan Sunday This code may be freely used and modified for any purpose providing that this copyright notice is included with it. iSurfer.org makes no warranty for this code, and cannot be held liable for any real or imagined damage resulting from its use. Users of this code must verify correctness for their application.
p
is not given, the listed order of the coordinates c
establishes the path. function polygon3d_area | ( | c | , |
p | , | ||
n | |||
) |
Compute the area of a polygon in a Euclidean 3d-space.
c | <coords-3d> A list of 3d cartesian coordinates [[x, y, z], ...]. |
p | <integer-list-list> An optional list of paths that define one or more closed shapes where each is a list of coordinate indexes. |
n | <vector-3d> An optional normal vector, [x, y, z], to the polygon plane. When not given, a normal vector is constructed from the first three points of the primary path. |
Function patterned after Dan Sunday, 2012.
p
is not given, the listed order of the coordinates c
establishes the path. function polyhedron_area | ( | c | , |
f | |||
) |
Compute the surface area of a polyhedron in a Euclidean 3d-space.
c | <coords-3d> A list of 3d cartesian coordinates [[x, y, z], ...]. |
f | <integer-list-list> A list of faces that enclose the shape where each face is a list of coordinate indexes. |
function polyhedron_centroid_tf | ( | c | , |
f | |||
) |
Compute the center of mass of a triangulated polyhedron in a Euclidean 3d-space.
c | <coords-3d> A list of 3d cartesian coordinates [[x, y, z], ...]. |
f | <integer-list-3-list> A list of triangular faces that enclose the polyhedron where each face is a list of three coordinate indexes. |
See Wikipedia for more information on centroid determined via the divergence theorem and midpoint quadrature.
function polyhedron_volume_tf | ( | c | , |
f | |||
) |
Compute the volume of a triangulated polyhedron in a Euclidean 3d-space.
c | <coords-3d> A list of 3d cartesian coordinates [[x, y, z], ...]. |
f | <integer-list-3-list> A list of triangular faces that enclose the polyhedron where each face is a list of three coordinate indexes. |
See Wikipedia for more information on volumes determined using the divergence theorem.
function polytope_bbox_pf | ( | c | , |
f | , | ||
a | |||
) |
Generate a bounding box polytope for another polytope in 3d or 2d.
c | <coords-3d|coords-2d> A list of 3d or 2d cartesian coordinates [[x, y (, z)], ...]. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
a | <decimal-list-1:3|decimal> The box padding. A list of lengths to equally pad the box dimensions. |
[points, faces]
, where points
are <coords-3d> and faces
are a <integer-list-list>, that define the bounding box of the given polyhedron. Or: (2) [points, path]
, where points
are <coords-2d> and path
is a <integer-list-list>, that define the bounding box of the given polygon.Polyhedron faces will be ordered clockwise when looking from outside the shape inwards. Polygon path will be ordered clockwise when looking from the top (positive z) downwards.
f
is not specified, all coordinates are used to determine the geometric limits, which, simplifies the calculation. Parameter f
is needed when a subset of the coordinates should be considered.function polytope_edge_af | ( | f | , |
e | , | ||
i | |||
) |
List the adjacent face indexes for a polytope edge.
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
e | <integer-list-2-list> A list of edges where each edge is a list of two coordinate indexes. |
i | <integer> The edge index. |
e
is not specified, it is computed from f
using polytope_faces2edges(). function polytope_edge_angles | ( | c | , |
f | |||
) |
List the adjacent edge angles for each polytope vertex.
c | <coords-3d|coords-2d> A list of 3d or 2d cartesian coordinates [[x, y (, z)], ...]. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
function polytope_edge_lengths | ( | c | , |
e | |||
) |
List the edge lengths of a polytope.
c | <coords-3d|coords-2d> A list of 3d or 2d cartesian coordinates [[x, y (, z)], ...]. |
e | <integer-list-2-list> A list of edges where each edge is a list of two coordinate indexes. |
function polytope_edge_n | ( | c | , |
f | , | ||
e | , | ||
i | |||
) |
Get a normal vector for a polytope edge.
c | <coords-3d|coords-2d> A list of 3d or 2d coordinate points. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
e | <integer-list-2-list> A list of edges where each edge is a list of two coordinate indexes. |
i | <integer> The edge index. |
The normal is computed as the mean of the adjacent faces.
f
is optional for polygons. When it is not given, the listed order of the coordinates c
establishes the polygon path. e
is not specified, it is computed from f
using polytope_faces2edges() iff the line is identified by i
. function polytope_face_angles | ( | c | , |
f | |||
) |
List the angles between all adjacent faces of a polyhedron.
c | <coords-3d> A list of 3d cartesian coordinates [[x, y, z], ...]. |
f | <integer-list-list> A list of faces that enclose the shape where each face is a list of coordinate indexes. |
See Wikipedia for more information on dihedral angles.
function polytope_face_m | ( | c | , |
f | , | ||
i | , | ||
l | |||
) |
Get the mean coordinate of all vertices of a polytope face.
c | <coords-3d|coords-2d> A list of 3d or 2d coordinate points. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
i | <integer> The face specified as an face index. |
l | <integer-list> The face specified as a list of all the coordinate indexes that define it. |
The face can be identified using either parameter i
or l
. When using l
, the parameter f
is not required.
f
is optional for polygons. When it is not given, the listed order of the coordinates c
establishes the polygon path. function polytope_face_mn | ( | c | , |
f | , | ||
i | , | ||
l | , | ||
cw | = true |
||
) |
Get the mean coordinate and normal vector of a polytope face.
c | <coords-3d|coords-2d> A list of 3d or 2d coordinate points. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
i | <integer> The face specified as an face index. |
l | <integer-list> The face specified as a list of all the coordinate indexes that define it. |
cw | <boolean> Face vertex ordering. |
[mp, nv]
, where mp
is coords-3d
, the mean coordinate, and nv
is vector-3d
, the normal vector, of the polytope face-plane.The face can be identified using either parameter i
or l
. When using l
, the parameter f
is not required.
f
is optional for polygons. When it is not given, the listed order of the coordinates c
establishes the polygon path. function polytope_face_n | ( | c | , |
f | , | ||
i | , | ||
l | , | ||
cw | = true |
||
) |
Get the normal vector of a polytope face.
c | <coords-3d|coords-2d> A list of 3d or 2d coordinate points. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
i | <integer> The face specified as an face index. |
l | <integer-list> The face-plane specified as a list of three or more coordinate indexes that are a part of the face. |
cw | <boolean> Face vertex ordering. |
The face can be identified using either parameter i
or l
. When using l
, the parameter f
is not required.
f
is optional for polygons. When it is not given, the listed order of the coordinates c
establishes the polygon path. function polytope_face_vcounts | ( | f | ) |
List the vertex counts for all polytope faces.
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
function polytope_faces2edges | ( | f | ) |
List the edge coordinate index pairs of a polytope.
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
function polytope_faces_are_regular | ( | c | , |
f | , | ||
e | , | ||
d | = 6 |
||
) |
Test if the faces of a polytope are all regular.
c | <coords-3d|coords-2d> A list of 3d or 2d cartesian coordinates [[x, y (, z)], ...]. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
e | <integer-list-2-list> A list of edges where each edge is a list of two coordinate indexes. |
d | <integer> The number of significant figures used when comparing lengths and angles. |
e
is not specified, it is computed from f
using polytope_faces2edges(). function polytope_limits | ( | c | , |
f | , | ||
a | , | ||
d | = [0:2] , |
||
s | = true |
||
) |
Determine the bounding limits of a polytope.
c | <coords-3d|coords-2d> A list of 3d or 2d cartesian coordinates [[x, y (, z)], ...]. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
a | <decimal-list-1:3|decimal> The box padding. A list of lengths to equally pad the box dimensions. |
d | <range|list|integer> The dimensions to consider. A range of dimensions, a list of dimensions, or a single dimension. |
s | <boolean> Return box size rather than coordinate limits. |
The returned list will be of the following form:
s | x | y | z | datastruct form | |
---|---|---|---|---|---|
2d | false | [min,max] | [min,max] | - | decimal-list-2-list-2 |
2d | true | max-min | max-min | - | decimal-list-list-2 |
3d | false | [min,max] | [min,max] | [min,max] | decimal-list-2-list-3 |
3d | true | max-min | max-min | max-min | decimal-list-list-3 |
f
is not specified, all coordinates are used to determine the geometric limits, which, simplifies the calculation. Parameter f
is needed when a subset of the coordinates should be considered. function polytope_line | ( | c | , |
f | , | ||
e | , | ||
i | , | ||
l | , | ||
r | = false |
||
) |
Get a line from an edge or any two vetices of a polytope.
c | <coords-3d|coords-2d> A list of 3d or 2d coordinate points. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
e | <integer-list-2-list> A list of edges where each edge is a list of two coordinate indexes. |
i | <integer> A line specified as an edge index. |
l | <integer-list-2> A line specified as a list of coordinate index pairs. |
r | <boolean> Reverse the line start and end points. |
f
is optional for polygons. When it is not given, the listed order of the coordinates c
establishes the polygon path. e
is not specified, it is computed from f
using polytope_faces2edges() iff the line is identified by i
. function polytope_plane | ( | c | , |
f | , | ||
i | , | ||
l | , | ||
cw | = true |
||
) |
Get a plane for a polytope face.
c | <coords-3d|coords-2d> A list of 3d or 2d coordinate points. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
i | <integer> The face specified as an face index. |
l | <integer-list> The face specified as a list of all the coordinate indexes that define it. |
cw | <boolean> Face vertex ordering. |
[mp, nv]
, where mp
is coords-3d
, the mean coordinate, and nv
is vector-3d
, the normal vector, of the polytope face-plane.The face can be identified using either parameter i
or l
. When using l
, the parameter f
is not required.
f
is optional for polygons. When it is not given, the listed order of the coordinates c
establishes the polygon path. function polytope_triangulate_ft | ( | f | ) |
Triangulate the faces of a convex polytope using fan triangulation.
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
See Wikipedia for more information on fan triangulation.
function polytope_vertex_af | ( | f | , |
i | |||
) |
List the adjacent face indexes for a polytope vertex.
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
i | <integer> The vertex index. |
function polytope_vertex_av | ( | f | , |
i | |||
) |
List the adjacent vertices for a given polytope vertex.
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
i | <integer> A vertex index. |
The adjacent vertices are those neighboring vertices that are directly connected to the given vertex by a common edge.
f
is optional for polygons. When it is not given, the listed order of the coordinates c
establishes the polygon path. function polytope_vertex_n | ( | c | , |
f | , | ||
i | |||
) |
Get a normal vector for a polytope vertex.
c | <coords-3d|coords-2d> A list of 3d or 2d coordinate points. |
f | <integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes. |
i | <integer> The vertex index. |
The normal is computed as the mean of the adjacent faces.
f
is optional for polygons. When it is not given, the listed order of the coordinates c
establishes the polygon path.