omdl  v0.9.5
OpenSCAD Mechanical Design Library
Polytopes

Polytope mathematical functions. More...

+ Collaboration diagram for Polytopes:

Files

file  polytope.scad
 Polytope shapes, conversions, properties, and tests functions.
 

General

function polytope_faces2edges (f)
 List the edge coordinate index pairs of a polytope. 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_limits (c, f, a, d, s=true)
 Determine the bounding limits of a polytope. More...
 
function polytope_bounding_box_pf (c, f, a)
 Generate a bounding box polytope for another polytope in 3d or 2d. More...
 
function polytope_ft_triangulate (f)
 Triangulate the faces of a convex polytope using fan triangulation. More...
 

Adjacents

function polytope_vertex_adjacent_vertices (f, i)
 List the adjacent vertices for a given polytope vertex. More...
 
function polytope_vertex_adjacent_faces (f, i)
 List the adjacent face indexes for a polytope vertex. More...
 
function polytope_edge_adjacent_faces (f, e, i)
 List the adjacent face indexes for a polytope edge. More...
 

Normals

function polytope_vertex_normal (c, f, i)
 Get a normal vector for a polytope vertex. More...
 
function polytope_edge_normal (c, f, e, i)
 Get a normal vector for a polytope edge. More...
 
function polytope_face_normal (c, f, i, l, cw=true)
 Get the normal vector of a polytope face. More...
 

Faces

function polytope_face_mean (c, f, i, l)
 Get the mean coordinate of all vertices of a polytope face. More...
 
function polytope_face_mean_normal (c, f, i, l, cw=true)
 Get the mean coordinate and normal vector of a polytope face. More...
 
function polytope_face_plane (c, f, i, l, cw=true)
 Get a plane for a polytope face. More...
 
function polytope_face_vertex_counts (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...
 

Edges

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...
 

Tests

function polytope_faces_are_regular (c, f, e, d=6)
 Test if the faces of a polytope are all regular. More...
 

Detailed Description

Polytope mathematical functions.

Requires:
include <omdl-base.scad>;

Function Documentation

◆ polytope_bounding_box_pf()

function polytope_bounding_box_pf ( ,
,
 
)

Generate a bounding box polytope for another polytope in 3d or 2d.

Parameters
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.
Returns
<datastruct> A structure: (1) [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.

Note
When 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.
See also
polytope_limits for warning about secondary Shapes.

◆ polytope_edge_adjacent_faces()

function polytope_edge_adjacent_faces ( ,
,
 
)

List the adjacent face indexes for a polytope edge.

Parameters
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.
Returns
<integer-list> The list of face indexes adjacent to the given polytope edge.
Note
When e is not specified, it is computed from f using polytope_faces2edges().

◆ polytope_edge_angles()

function polytope_edge_angles ( ,
 
)

List the adjacent edge angles for each polytope vertex.

Parameters
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.
Returns
<decimal-list> A list of the polytope adjacent edge angles.

◆ polytope_edge_lengths()

function polytope_edge_lengths ( ,
 
)

List the edge lengths of a polytope.

Parameters
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.
Returns
<decimal-list> A list of the polytope edge lengths.

◆ polytope_edge_normal()

function polytope_edge_normal ( ,
,
,
 
)

Get a normal vector for a polytope edge.

Parameters
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.
Returns
<vector-3d> A normal vector for the polytope edge.

The normal is computed as the mean of the adjacent faces.

Note
Parameter f is optional for polygons. When it is not given, the listed order of the coordinates c establishes the polygon path.
When e is not specified, it is computed from f using polytope_faces2edges().
+ Here is the caller graph for this function:

◆ polytope_face_angles()

function polytope_face_angles ( ,
 
)

List the angles between all adjacent faces of a polyhedron.

Parameters
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.
Returns
<decimal-list> A list of the polyhedron adjacent face angles.

See Wikipedia for more information on dihedral angles.

◆ polytope_face_mean()

function polytope_face_mean ( ,
,
,
 
)

Get the mean coordinate of all vertices of a polytope face.

Parameters
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.
Returns
<coords-3d> The mean coordinate of a polytope face.

The face can be identified using either parameter i or l. When using l, the parameter f is not required.

Note
Parameter f is optional for polygons. When it is not given, the listed order of the coordinates c establishes the polygon path.
+ Here is the caller graph for this function:

◆ polytope_face_mean_normal()

function polytope_face_mean_normal ( ,
,
,
,
cw  = true 
)

Get the mean coordinate and normal vector of a polytope face.

Parameters
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.
Returns
<plane> [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.

Note
Parameter f is optional for polygons. When it is not given, the listed order of the coordinates c establishes the polygon path.

◆ polytope_face_normal()

function polytope_face_normal ( ,
,
,
,
cw  = true 
)

Get the normal vector of a polytope face.

Parameters
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.
Returns
<vector-3d> The normal vector of a polytope face.

The face can be identified using either parameter i or l. When using l, the parameter f is not required.

Note
Parameter f is optional for polygons. When it is not given, the listed order of the coordinates c establishes the polygon path.
+ Here is the caller graph for this function:

◆ polytope_face_plane()

function polytope_face_plane ( ,
,
,
,
cw  = true 
)

Get a plane for a polytope face.

Parameters
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.
Returns
<plane> [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.

Note
Parameter f is optional for polygons. When it is not given, the listed order of the coordinates c establishes the polygon path.

◆ polytope_face_vertex_counts()

function polytope_face_vertex_counts ( )

List the vertex counts for all polytope faces.

Parameters
f<integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes.
Returns
<integer-list> A list with a vertex count of every face.

◆ polytope_faces2edges()

function polytope_faces2edges ( )

List the edge coordinate index pairs of a polytope.

Parameters
f<integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes.
Returns
<integer-list-2-list> A list of edges where each edge is a list of two coordinate indexes that form the shape.
Note
Although the edge list is not sorted, each pair is sorted with the smallest index first.
+ Here is the caller graph for this function:

◆ polytope_faces_are_regular()

function polytope_faces_are_regular ( ,
,
,
= 6 
)

Test if the faces of a polytope are all regular.

Parameters
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.
Returns
<boolean> true when there is both a single edge length and a single edge angle and false otherwise.
Note
When e is not specified, it is computed from f using polytope_faces2edges().

◆ polytope_ft_triangulate()

function polytope_ft_triangulate ( )

Triangulate the faces of a convex polytope using fan triangulation.

Parameters
f<integer-list-list> A list of faces (or paths) that enclose the shape where each face is a list of coordinate indexes.
Returns
<integer-list-3-list> A list of triangular faces that enclose the polytope where each face is a list of three coordinate indexes with vertex ordering is maintained.

See Wikipedia for more information on fan triangulation.

Warning
This method does not support concave polytopes.

◆ polytope_limits()

function polytope_limits ( ,
,
,
,
= true 
)

Determine the bounding limits of a polytope.

Parameters
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.
Returns
<datastruct> The bounding-box limits (see: table).

The returned datastruct will be one of the following forms:

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
Note
When 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.
When d is not specified, a check will be performed to see if all coordinates of c are 3, 2, or 1 dimensional and, if so, all axes for the determined dimension will be used for d.
Warning
This function does not track secondary shapes subtraction as implemented by the polygon() function.
+ Here is the caller graph for this function:

◆ polytope_line()

function polytope_line ( ,
,
,
,
,
= false 
)

Get a line from an edge or any two vetices of a polytope.

Parameters
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 start and end points of the line specified as an edge index i.
Returns
<line-3d | line-2d> The line as a pair of coordinates.
Note
Parameter f is optional for polygons. When it is not given, the listed order of the coordinates c establishes the polygon path.
When e is not specified, it is computed from f using polytope_faces2edges() iff the line is identified by i.

◆ polytope_vertex_adjacent_faces()

function polytope_vertex_adjacent_faces ( ,
 
)

List the adjacent face indexes for a polytope vertex.

Parameters
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.
Returns
<integer-list> The list of face indexes adjacent to the given polytope vertex.

◆ polytope_vertex_adjacent_vertices()

function polytope_vertex_adjacent_vertices ( ,
 
)

List the adjacent vertices for a given polytope vertex.

Parameters
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.
Returns
<integer-list> The list of adjacent vertex indexes for the given vertex index.

The adjacent vertices are those neighboring vertices that are directly connected to the given vertex by a common edge.

Note
Parameter f is optional for polygons. When it is not given, the listed order of the coordinates c establishes the polygon path.

◆ polytope_vertex_normal()

function polytope_vertex_normal ( ,
,
 
)

Get a normal vector for a polytope vertex.

Parameters
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.
Returns
<vector-3d> A normal vector for the polytope vertex.

The normal is computed as the mean of the adjacent faces.

Note
Parameter f is optional for polygons. When it is not given, the listed order of the coordinates c establishes the polygon path.
+ Here is the caller graph for this function: