|
EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
|
Signed distance field for a convex polyhedron: the intersection of the half-spaces behind a set of planes, such as a regular (Platonic) solid or a pyramid. More...
#include <EBGeometry_AnalyticDistanceFunctions.hpp>

Public Member Functions | |
| ConvexPolyhedronSDF () | |
| Default constructor. Constructs the cube [-0.5, 0.5]^3. | |
| ConvexPolyhedronSDF (const std::vector< PlaneSDF< T > > &a_planes) | |
| Constructs the convex polyhedron bounded by a set of planes: the points behind every plane. | |
| ConvexPolyhedronSDF (const ConvexPolyhedronSDF &)=default | |
| Copy constructor. | |
| ConvexPolyhedronSDF (ConvexPolyhedronSDF &&)=default | |
| Move constructor. | |
| ConvexPolyhedronSDF & | operator= (const ConvexPolyhedronSDF &)=default |
| Copy assignment. | |
| ConvexPolyhedronSDF & | operator= (ConvexPolyhedronSDF &&)=default |
| Move assignment. | |
| uint32_t | getNumFaces () const noexcept |
| Get the number of faces. | |
| const Vec3T< T > & | getNormal (const uint32_t a_face) const noexcept |
| Get the unit outward normal of a face. | |
| const T & | getOffset (const uint32_t a_face) const noexcept |
| Get the offset of a face's plane: the plane is the points x with dot(getNormal(a_face), x) equal to it. | |
| uint32_t | getNumVertices () const noexcept |
| Get the number of vertices. | |
| const Vec3T< T > & | getVertex (const uint32_t a_vertex) const noexcept |
| Get a vertex. | |
| uint32_t | getNumEdges () const noexcept |
| Get the number of edges. | |
| uint32_t | getEdgeVertex (const uint32_t a_edge, const uint32_t a_end) const noexcept |
| Get one end of an edge. | |
| T | signedDistance (const Vec3T< T > &a_point) const noexcept |
| Signed distance function for the polyhedron. | |
| uint32_t | getNumParts () const noexcept |
| How many parts the shape has (see hasParts): its faces, getNumFaces(). | |
| uint32_t | closestPart (const Vec3T< T > &a_point) const noexcept |
| The part whose term decides the value at a point (see hasParts): the face whose plane is farthest above the point (the lowest such face on a tie). Inside, that is the nearest face; outside, the face the nearest point is on whenever that point is inside a face. | |
| BoundingVolumes::AABBT< T > | computeBoundingVolume () const noexcept |
| The shape's axis-aligned bounding box: that of its vertices. | |
Static Public Member Functions | |
| static ConvexPolyhedronSDF | tetrahedron (const Vec3T< T > &a_center, T a_radius) |
| A regular tetrahedron. | |
| static ConvexPolyhedronSDF | octahedron (const Vec3T< T > &a_center, T a_radius) |
| A regular octahedron. | |
| static ConvexPolyhedronSDF | dodecahedron (const Vec3T< T > &a_center, T a_radius) |
| A regular dodecahedron. | |
| static ConvexPolyhedronSDF | icosahedron (const Vec3T< T > &a_center, T a_radius) |
| A regular icosahedron. | |
| static ConvexPolyhedronSDF | pyramid (const Vec3T< T > &a_baseCenter, const Vec3T< T > &a_apex, T a_radius, unsigned a_sides, const Vec3T< T > &a_vertexDirection) |
| A right pyramid on a regular polygon: a square pyramid with four sides, a tetrahedron-like one with three. | |
Static Public Attributes | |
| static constexpr DistanceQuality | distanceQuality = DistanceQuality::Exact |
| How far signedDistance() can be trusted as a distance: the Euclidean distance to the surface. | |
| static constexpr uint32_t | MaxFaces = 20U |
| The most faces a polyhedron can have: those of the icosahedron. | |
| static constexpr uint32_t | MaxVertices = 20U |
| The most vertices a polyhedron can have: those of the dodecahedron. | |
| static constexpr uint32_t | MaxEdges = MaxFaces + MaxVertices - 2U |
| The most edges a polyhedron can have, from Euler's formula: MaxFaces + MaxVertices - 2. | |
Protected Member Functions | |
| void | build (const std::vector< Vec3T< double > > &a_points, const std::vector< Vec3T< double > > &a_normals, double a_epsilon) |
| Sets the polyhedron to the one bounded by planes given in double precision: finds its vertices and edges, and checks it (see the constructor from planes). | |
Static Protected Member Functions | |
| static std::vector< PlaneSDF< T > > | cubePlanes () |
| The six planes of the cube [-0.5, 0.5]^3, the default polyhedron. | |
| static std::vector< Vec3T< T > > | goldenDirections (T a_small, T a_large) |
| The twelve directions (0, +-a, +-b), (+-a, +-b, 0) and (+-b, 0, +-a), in that order, the signs within each group in the order (+, +), (+, -), (-, +), (-, -). | |
| static ConvexPolyhedronSDF | fromNormals (const Vec3T< T > &a_center, const std::vector< Vec3T< T > > &a_vertexDirections, const std::vector< Vec3T< T > > &a_normals, T a_radius, const char *a_who) |
| A regular solid from the directions of its vertices and of its faces' normals: each face's plane is as far out along its normal as the farthest vertex, the vertices being at the circumradius from the center. | |
Protected Attributes | |
| uint32_t | m_numFaces = 0U |
| Number of faces. | |
| uint32_t | m_numVertices = 0U |
| Number of vertices. | |
| uint32_t | m_numEdges = 0U |
| Number of edges. | |
| Array< Vec3T< T >, MaxFaces > | m_normals |
| Unit outward normal of each face. | |
| Array< T, MaxFaces > | m_offsets |
| Offset of each face's plane along its normal. | |
| Array< Vec3T< T >, MaxVertices > | m_vertices |
| The vertices. | |
| Array< uint8_t, 2U *MaxEdges > | m_edges |
| The edges, as the indices of their two vertices: edge e from m_edges[2 e] to m_edges[2 e + 1]. | |
Signed distance field for a convex polyhedron: the intersection of the half-spaces behind a set of planes, such as a regular (Platonic) solid or a pyramid.
The distance is exact. Inside, it is that to the nearest face plane. Outside, it is that to the face whose plane is farthest from the point when the point's projection onto that plane lies on the face, and otherwise that to the nearest edge or vertex: the largest plane distance alone, which is all most formulas take, is a bound at the edges and corners. The faces, edges and vertices are held in the shape itself, in arrays of fixed size, so the polyhedron is trivially copyable and needs no pool; it has at most MaxFaces faces and MaxVertices vertices. A polyhedron larger than that is a mesh (MeshSDF, TriMeshSDF), which has no limit.
The regular solids and the pyramid are made by the static functions tetrahedron(), octahedron(), dodecahedron(), icosahedron() and pyramid(), which return a ConvexPolyhedronSDF; any other convex polyhedron is made from its planes, with the constructor. A box is BoxSDF and a regular prism PolygonPrismSDF, both cheaper to evaluate than the same solid as a polyhedron. Round its edges with Offset of a slightly smaller polyhedron. By default the polyhedron is the cube [-0.5, 0.5]^3.
| T | Floating-point precision. |
|
inlineexplicit |
Constructs the convex polyhedron bounded by a set of planes: the points behind every plane.
Runs on the host. The vertices and edges are found from the planes, in double precision, to within a few units in the last place of T times the size of the coordinates. In float, a solid much smaller than its distance from the origin can therefore not be told apart from rounding: build it near the origin and move it with Translate. Face k is the face on plane k, which is also the shape's part k.
| [in] | a_planes | The planes, each with its normal pointing out of the solid (PlaneSDF's sign: the solid is where every plane's value is negative). There must be from 4 to MaxFaces of them, each must bound a face of the solid (no plane may miss it or only touch it at an edge or a vertex), the solid they bound must be finite and have a volume, and it must have at most MaxVertices vertices. |
|
inlineprotected |
Sets the polyhedron to the one bounded by planes given in double precision: finds its vertices and edges, and checks it (see the constructor from planes).
| [in] | a_points | A point on each plane. |
| [in] | a_normals | Each plane's outward normal, not necessarily of unit length. |
| [in] | a_epsilon | The machine epsilon of the precision the planes are exact in, which sets the tolerance for where they meet. |
|
inlinenoexcept |
The part whose term decides the value at a point (see hasParts): the face whose plane is farthest above the point (the lowest such face on a tie). Inside, that is the nearest face; outside, the face the nearest point is on whenever that point is inside a face.
| [in] | a_point | Position. |
|
inlinenoexcept |
The shape's axis-aligned bounding box: that of its vertices.
|
inlinestaticprotected |
The six planes of the cube [-0.5, 0.5]^3, the default polyhedron.
|
inlinestatic |
A regular dodecahedron.
In its standard orientation, in which the three coordinate planes through the center are mirror planes: its vertices are in the directions (+-1, +-1, +-1), (0, +-1/phi, +-phi), (+-1/phi, +-phi, 0) and (+-phi, 0, +-1/phi), with phi the golden ratio; turn it with Rotate. Its twelve faces have their outward normals along (0, +-phi, +-1), (+-phi, +-1, 0) and (+-1, 0, +-phi), numbered in that order, the signs within each group in the order (+, +), (+, -), (-, +), (-, -).
| [in] | a_center | Center. |
| [in] | a_radius | Circumradius: the distance from the center to a vertex, finite and positive. |
|
inlinestaticprotected |
A regular solid from the directions of its vertices and of its faces' normals: each face's plane is as far out along its normal as the farthest vertex, the vertices being at the circumradius from the center.
| [in] | a_center | Center. |
| [in] | a_vertexDirections | Directions from the center to the vertices. |
| [in] | a_normals | The faces' outward normals, in the faces' order. |
| [in] | a_radius | Circumradius, finite and positive. |
| [in] | a_who | The factory's name, for the messages. |
|
inlinenoexcept |
Get one end of an edge.
| [in] | a_edge | The edge, below getNumEdges(). |
| [in] | a_end | 0 or 1. |
|
inlinenoexcept |
Get the unit outward normal of a face.
| [in] | a_face | The face, below getNumFaces(). |
|
inlinenoexcept |
Get the number of edges.
|
inlinenoexcept |
Get the number of faces.
|
inlinenoexcept |
How many parts the shape has (see hasParts): its faces, getNumFaces().
|
inlinenoexcept |
Get the number of vertices.
|
inlinenoexcept |
Get the offset of a face's plane: the plane is the points x with dot(getNormal(a_face), x) equal to it.
| [in] | a_face | The face, below getNumFaces(). |
|
inlinenoexcept |
|
inlinestaticprotected |
The twelve directions (0, +-a, +-b), (+-a, +-b, 0) and (+-b, 0, +-a), in that order, the signs within each group in the order (+, +), (+, -), (-, +), (-, -).
| [in] | a_small | The first magnitude, a. |
| [in] | a_large | The second magnitude, b. |
|
inlinestatic |
A regular icosahedron.
In its standard orientation, in which the three coordinate planes through the center are mirror planes: its vertices are in the directions (0, +-1, +-phi), (+-1, +-phi, 0) and (+-phi, 0, +-1), with phi the golden ratio; turn it with Rotate. Its twenty faces have their outward normals along (+-1, +-1, +-1), (0, +-phi, +-1/phi), (+-phi, +-1/phi, 0) and (+-1/phi, 0, +-phi), numbered in that order: the first eight with the signs of x, y and z counted as the bits of 4 i + 2 j + k (a minus sign for a set bit), the others with their two signs in the order (+, +), (+, -), (-, +), (-, -).
| [in] | a_center | Center. |
| [in] | a_radius | Circumradius: the distance from the center to a vertex, finite and positive. |
|
inlinestatic |
A regular octahedron.
Its six vertices are on the coordinate axes through the center, so that the solid is |x| + |y| + |z| <= radius around it; turn it with Rotate. Face 4 i + 2 j + k is the one whose outward normal is ((-1)^i, (-1)^j, (-1)^k) / sqrt(3). The inradius is the circumradius over sqrt(3).
| [in] | a_center | Center. |
| [in] | a_radius | Circumradius: the distance from the center to a vertex, finite and positive. |
|
default |
Copy assignment.
|
default |
Move assignment.
|
inlinestatic |
A right pyramid on a regular polygon: a square pyramid with four sides, a tetrahedron-like one with three.
As for PolygonPrismSDF, the base is a regular polygon of n sides around the axis from the base center to the apex, with one vertex along the given direction. Faces 0 to n - 1 are the sides, counted around the axis from the one that starts at that vertex, as PolygonPrismSDF counts its sides; face n is the base.
| [in] | a_baseCenter | Center of the base. |
| [in] | a_apex | The apex; it must differ from a_baseCenter. |
| [in] | a_radius | Circumradius of the base: the distance from the axis to a base vertex, finite and positive. |
| [in] | a_sides | Number of sides, from 3 to MaxVertices - 1. |
| [in] | a_vertexDirection | Direction from the axis toward one base vertex. Only its part across the axis is used, and that must not be zero. |
|
inlinenoexcept |
Signed distance function for the polyhedron.
Out of line on a device (its loops over the faces and edges are the whole distance): inlined, it would be copied into every level of every tape kernel, whatever shapes the tape holds, which makes the device compile of every tape kernel much slower. A call costs little beside those loops.
| [in] | a_point | Position. |
|
inlinestatic |
A regular tetrahedron.
Its vertices are at four alternate corners of a cube around the center, in the directions (1, 1, 1), (1, -1, -1), (-1, 1, -1) and (-1, -1, 1), in that order; turn it with Rotate. Face k is the one opposite vertex k. The inradius is a third of the circumradius.
| [in] | a_center | Center. |
| [in] | a_radius | Circumradius: the distance from the center to a vertex, finite and positive. |