geomc 1.0
A c++ linear algebra template library
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
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, Derived >

Public Types

typedef PointType< T, N >::point_t point_t
 
typedef T elem_t
 The coordinate type of this shape.
 

Public Member Functions

 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.
 
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.
 
bool operator== (const Simplex< T, N > &other) const
 Simplex equality check. More...
 
bool operator!= (const Simplex< T, N > &other) const
 Simplex inequality check.
 
Simplex< T, Noperator| (const Vec< T, N > &p) const
 Return a copy of this simplex with an additional vertex at p. More...
 
Simplex< T, N > & operator|= (const Vec< T, N > &p)
 Extend this simplex to include p by adding p as a vertex. More...
 
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.
 
Rect< T, 1 > intersect (const Ray< T, N > &r) const
 Ray-shape intersection. More...
 
bool projection_contains (const Vec< T, N > &p, Vec< T, N > *params=nullptr) const
 Project the point to the simplex along its orthogonal basis (if there is one) and test for containment. More...
 
volume () const
 Compute the volume of the simplex. More...
 
bool contains (const Vec< T, N > &p) const
 Simplex-point intersection test. More...
 
sdf (Vec< T, N > p) const
 Return the signed distance to the surface of the shape.
 
Simplex< T, Nexclude (index_t i) const
 Create a new sub-simplex by excluding the ith vertex in this simplex.
 
Vec< T, Nproject (const Vec< T, N > &p, Simplex< T, N > *onto=nullptr) const
 Project p to the nearest point on the simplex. More...
 
Rect< T, Nbounds () const
 
Vec< T, Nconvex_support (Vec< T, N > d) const
 
bool intersects (const Convex< T, N, Shape > &other) const
 Convex shape overlap test. More...
 
bool contains (Vec< T, N > p) const
 Shape-point overlap test. More...
 

Public Attributes

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

Static Public Attributes

static constexpr size_t N = _N
 The dimension of this shape.
 

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 Function Documentation

◆ contains() [1/2]

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.

◆ contains() [2/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.

◆ intersect()

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.

◆ operator==()

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

Simplex equality check.

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

◆ operator|()

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|=()

Simplex< T, N > & operator|= ( const 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 operator has no effect.

◆ project()

Vec< T, N > project ( const Vec< T, N > &  p,
Simplex< T, N > *  onto = nullptr 
) const
inline

Project p to the nearest point on the simplex.

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.

◆ projection_contains()

bool projection_contains ( const Vec< T, N > &  p,
Vec< T, N > *  params = nullptr 
) const
inline

Project the point to the simplex along its orthogonal basis (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.

◆ volume()

T volume ( ) const
inline

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


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