geomc 1.0
A c++ linear algebra template library
Loading...
Searching...
No Matches
Simplex< T, N > Class Template Reference

A simplex in N dimensions (e.g. a tetrahedron, triangle, line, point). More...

#include <geomc/shape/Simplex.h>

Inheritance diagram for Simplex< T, N >:
Convex< T, N, Simplex< T, N > > RayIntersectable< T, N, Simplex< T, N > > SdfEvaluable< T, N, Simplex< T, N > > Bounded< T, N, Simplex< T, N > > Dimensional< T, N >

Public Types

using elem_t
 The coordinate type of this object.
 
using point_t
 The type of a point in this object's space.
 

Public Member Functions

constexpr Simplex ()
 Construct an empty simplex, with no vertices.
 
 Simplex (const Vec< T, N > *verts, index_t n)
 Construct an n-cornered simplex with vertices at verts.
 
 Simplex (std::initializer_list< Vec< T, N > > verts)
 
Vec< T, Nbarycenter () const
 Compute the barycenter of this simplex.
 
Rect< T, Nbounds () const
 Produces an axis-aligned box completely enclosing this shape.
 
Vec< T, Nclip (const Vec< T, N > &p, Simplex< T, N > *onto=nullptr) const
 Ensure p lies within the simplex by orthogonally projecting it to the nearest point on the surface if it lies outside.
 
bool contains (Vec< T, N > p) const
 Shape-point overlap test.
 
bool contains (const Vec< T, N > &p) const
 Simplex-point intersection test.
 
Vec< T, Nconvex_support (Vec< T, N > d) const
 
void exclude (index_t i)
 
Simplex< T, Nexcluded (index_t i) const
 Create a new sub-simplex by excluding the ith vertex in this simplex.
 
void insert (Vec< T, N > p)
 Extend this simplex to include p by adding p as a vertex.
 
Rect< T, 1 > intersect (const Ray< T, N > &r) const
 Ray-shape intersection.
 
bool intersects (const Convex< T, N, Shape > &other) const
 Convex shape overlap test.
 
bool is_facing (const Vec< T, N > &p, Vec< T, N > *params=nullptr) const
 Project the point to the simplex along its orthogonal complement (if there is one) and test for containment.
 
measure () const
 Return the positive volume of the simplex within the subspace that it spans.
 
measure_interior () const
 Compute the signed volume of the simplex.
 
Vec< T, Nnormal (Vec< T, N > p) const
 
bool operator!= (const Simplex< T, N > &other) const
 Simplex inequality check.
 
Simplex< T, N > & operator*= (const AffineTransform< T, N > &xf)
 Apply a transformation to the points of this Simplex.
 
Simplex< T, N > & operator/= (const AffineTransform< T, N > &xf)
 Apply an inverse transformation to the points of this Simplex.
 
bool operator== (const Simplex< T, N > &other) const
 Simplex equality check.
 
Vec< T, N > & operator[] (index_t i)
 Get the ith vertex in this simplex.
 
Vec< T, Noperator[] (index_t i) const
 Get the ith vertex in this simplex.
 
Simplex< T, Noperator| (const Vec< T, N > &p) const
 Return a copy of this simplex with an additional vertex at p.
 
Simplex< T, N > & operator|= (const Vec< T, N > &p)
 Extend this simplex to include p by adding p as a vertex.
 
Vec< T, Nproject (Vec< T, N > p, Simplex< T, N > *face=nullptr) const
 
sdf (Vec< T, N > p) const
 Signed distance function.
 
sdf (Vec< T, N > p, Vec< T, N > *normal=nullptr) const
 Return the signed distance to the surface of the shape.
 

Static Public Member Functions

static constexpr bool admits_cusps ()
 
static constexpr Simplex regular_simplex (index_t n=N+1)
 Construct a simplex with all edges of unit length and one edge along the x-axis.
 
static constexpr Simplex standard_simplex ()
 Construct a simplex with its vertices on the unit axes.
 

Public Attributes

index_t n
 Number of vertices in this simplex.
 
Vec< T, Npts [N+1]
 Vertices of this simplex.
 

Static Public Attributes

static constexpr index_t N
 The dimension of this object.
 

Detailed Description

template<typename T, index_t N>
class geom::Simplex< T, N >

A simplex in N dimensions (e.g. a tetrahedron, triangle, line, point).

The simplex may contain up to N + 1 points, in which case it encloses a volume, if it is not degenerate. If it contains fewer points, then it spans a subspace of the space in which it is embedded.

Member Typedef Documentation

◆ point_t

using point_t
inherited

The type of a point in this object's space.

An N-vector of T if N > 1, otherwise a T.

Member Function Documentation

◆ bounds()

Rect< T, N > bounds ( ) const
inlineinherited

Produces an axis-aligned box completely enclosing this shape.

The default implementation calls convex_support() along each of the principal axes to find the extents.

◆ clip()

template<typename T, index_t N>
Vec< T, N > clip ( const Vec< T, N > & p,
Simplex< T, N > * onto = nullptr ) const
inline

Ensure p lies within the simplex by orthogonally projecting it to the nearest point on the surface if it lies outside.

The point is unchanged if p is already inside the simplex.

Parameters
pThe point to project onto the surface of this simplex.
ontoOptional output parameter to receive the sub-simplex onto which p was projected. It is permissible for onto to alias this.
Returns
The location of p's projection.

◆ contains() [1/2]

bool contains ( Vec< T, N > p) const
inlineinherited

Shape-point overlap test.

Return true if the point p is on the surface or interior of the shape, false otherwise.

◆ contains() [2/2]

template<typename T, index_t N>
bool contains ( const Vec< T, N > & p) const
inline

Simplex-point intersection test.

If this simplex has fewer than N + 1 vertices, this simplex is not a volume, and this function returns false.

If the simplex is degenerate (two or more coincident points), then it is also considered empty and this function returns false.

Parameters
pA point.
Returns
true if p is on or inside this simplex; false otherwise.

◆ insert()

template<typename T, index_t N>
void insert ( Vec< T, N > p)
inline

Extend this simplex to include p by adding p as a vertex.

If this Simplex already has N+1 vertices, then this function has no effect.

◆ intersect()

template<typename T, index_t N>
Rect< T, 1 > intersect ( const Ray< T, N > & r) const
inline

Ray-shape intersection.

Return the interval over which the ray intersects the simplex.

If the simplex is N-1 dimensional (i.e., planar, like a triangle in 3D), then an intersecting interval will have both of its limits equal to the single value of s for which the ray o + s*v intersects the simplex.

Simplexes with fewer than N-1 dimensions cannot be intersected, and the interval will always be empty.

◆ intersects()

bool intersects ( const Convex< T, N, Shape > & other) const
inlineinherited

Convex shape overlap test.

Returns
True if and only if this convex shape overlaps other; false otherwise.

◆ is_facing()

template<typename T, index_t N>
bool is_facing ( const Vec< T, N > & p,
Vec< T, N > * params = nullptr ) const
inline

Project the point to the simplex along its orthogonal complement (if there is one) and test for containment.

Parameters
pA point.
paramsOptional return variable; return the n - 1 surface parameters of this simplex representing the projection of p onto the space spanned by this simplex.
Returns
true if p is on or inside this simplex after projection; false otherwise.

◆ measure()

template<typename T, index_t N>
T measure ( ) const
inline

Return the positive volume of the simplex within the subspace that it spans.

For example, if the simplex has three points, it spans a plane and this function returns the area within the plane. If it has four, it returns the volume of the tetrahedron; or if it has two, the length of the line segment; and so on.

Returns
T

◆ measure_interior()

template<typename T, index_t N>
T measure_interior ( ) const
inline

Compute the signed volume of the simplex.

If the simplex is not a full volume (i.e., the number of vertices is less than N+1), then its volume is zero.

◆ operator==()

template<typename T, index_t N>
bool operator== ( const Simplex< T, N > & other) const
inline

Simplex equality check.

Simplexes are equal if they have identical vertices in identical order.

◆ operator|()

template<typename T, index_t N>
Simplex< T, N > operator| ( const Vec< T, N > & p) const
inline

Return a copy of this simplex with an additional vertex at p.

If this simplex already has N + 1 points, a copy of this simplex is returned.

◆ operator|=()

template<typename T, index_t N>
Simplex< T, N > & operator|= ( const Vec< T, N > & p)
inline

Extend this simplex to include p by adding p as a vertex.

Alias for insert(p).

If this Simplex already has N+1 vertices, then this operator has no effect.

◆ regular_simplex()

template<typename T, index_t N>
static constexpr Simplex regular_simplex ( index_t n = N+1)
inlinestaticconstexpr

Construct a simplex with all edges of unit length and one edge along the x-axis.

n is the number of vertices in the simplex.

◆ sdf()

T sdf ( Vec< T, N > p) const
inlineinherited

Signed distance function.

Compute a signed distance to the nearest surface point on the shape. Points on the exterior have positive value; points on the interior have negative value; surface points have sdf value 0.


The documentation for this class was generated from the following files: