![]() |
omdl
v1.0
OpenSCAD Mechanical Design Library
|
Polyhedron mathematical functions; 3-polytope. More...
Collaboration diagram for Polyhedrons:Files | |
| file | polyhedron.scad |
| Polyhedron shapes, conversions, properties, and tests functions. | |
Properties | |
| function | polyhedron_area (c, f) |
| Compute the surface area of a polyhedron in a Euclidean 3d-space. More... | |
| function | polyhedron_tf_volume (c, f) |
| Compute the signed volume of a triangulated polyhedron in a Euclidean 3d-space. More... | |
| function | polyhedron_tf_centroid (c, f) |
| Compute the center of mass of a triangulated polyhedron in a Euclidean 3d-space. More... | |
Polyhedron mathematical functions; 3-polytope.
| file | group | script | results | no test | skipped | passed | failed | warning |
|---|---|---|---|---|---|---|---|---|
| math/polyhedron.scad | Polyhedrons | Script | Results | 3 | 0 | 0 | 0 | 0 |
See complete validation results.
| Requires: |
|---|
| include <omdl-base.scad>; |
All functions in this group operate on polyhedra defined by a list of 3d cartesian coordinates c and a list of faces f, following OpenSCAD's native polyhedron() convention:
[[x,y,z], ...].tf infix require that all faces be triangulated (exactly 3 vertex indices per face). Non-triangulated meshes must be tessellated before being passed to these functions. Passing a face with fewer or more than 3 indices to a tf function produces undef in the corresponding term and will silently corrupt the result. | function polyhedron_area | ( | c | , |
| f | |||
| ) |
Compute the surface area of a polyhedron in a Euclidean 3d-space.
| c | <points-3d> A list of 3d cartesian coordinates [[x, y, z], ...]. |
| f | <integer-list-list> A list of faces that enclose the polyhedron, where each face is a list of coordinate indexes. Faces may be polygons with any number of vertices >= 3 and need not be triangulated. |
The surface area is computed by summing the area of each face polygon via polygon3d_area(). Faces are not required to be triangular, but each face is assumed to be planar.
Example — unit cube (expected area = 6.0):
| function polyhedron_tf_volume | ( | c | , |
| f | |||
| ) |
Compute the signed volume of a triangulated polyhedron in a Euclidean 3d-space.
| c | <points-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 exactly three coordinate indexes. Non-triangular faces must be tessellated before calling this function; any face with a vertex count other than 3 is skipped (contributing 0 to the sum) and a warning is implicitly indicated by an undef guard — see note below. |
Volume is computed using the divergence theorem applied to a signed tetrahedral decomposition. For each triangular face with vertices
, the signed tetrahedral volume relative to the origin is:
The total volume is the sum over all faces:
This formula is exact for any closed, consistently wound triangulated mesh regardless of whether the mesh encloses the origin.
See Wikipedia: Polyhedron – Volume for background.
polyhedron() convention). Faces that do not satisfy len(fi)==3 are excluded from the summation via a filtered list comprehension, preventing silent undef corruption.abs() of the return value if the sign of winding is uncertain.Example — unit cube triangulated (expected volume = 1.0):
| function polyhedron_tf_centroid | ( | c | , |
| f | |||
| ) |
Compute the center of mass of a triangulated polyhedron in a Euclidean 3d-space.
| c | <points-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 exactly three coordinate indexes. Non-triangular faces must be tessellated before calling this function. |
c.The centroid is computed via the divergence theorem using first- order midpoint quadrature. For each triangular face with vertices
and signed weight
the centroid contribution is:
and the overall centroid is:
where
is the signed volume returned by polyhedron_tf_volume(). Volume and the weighted centroid sum are computed in a single pass over the face list to avoid redundant iteration.
Approximation notice: midpoint quadrature is exact only when the integrand is linear over each face. For a flat triangulated mesh this is exact; for curved or high-curvature approximations the error is
where
is the maximum edge length.
See Wikipedia: Centroid for background.
polyhedron() convention), consistent with polyhedron_tf_volume(). Faces that do not satisfy len(fi)==3 are excluded from the summation.Example — unit cube triangulated (expected centroid = [0.5, 0.5, 0.5]):