EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
EBGeometry::Triangle< T, Meta > Class Template Reference

Triangle class with signed distance functionality. More...

#include <EBGeometry_Triangle.hpp>

Collaboration diagram for EBGeometry::Triangle< T, Meta >:
Collaboration graph
[legend]

Public Types

using Vec2 = Vec2T< T >
 Alias for 2D vector type.
 
using Vec3 = Vec3T< T >
 Alias for 3D vector type.
 

Public Member Functions

 Triangle () noexcept=default
 Default constructor. Does not put the triangle in a usable state.
 
 Triangle (const Triangle &a_otherTriangle) noexcept=default
 Copy constructor.
 
 Triangle (Triangle &&a_otherTriangle) noexcept=default
 Move constructor.
 
 Triangle (const std::array< Vec3, 3 > &a_vertexPositions) noexcept
 Full constructor.
 
 ~Triangle () noexcept=default
 Destructor (does nothing).
 
Triangleoperator= (const Triangle &a_otherTriangle) noexcept=default
 Copy assignment.
 
Triangleoperator= (Triangle &&a_otherTriangle) noexcept=default
 Move assignment.
 
void setNormal (const Vec3 &a_normal) noexcept
 Set the triangle normal vector.
 
void setVertexPositions (const std::array< Vec3, 3 > &a_vertexPositions) noexcept
 Set the triangle vertex positions.
 
void setVertexNormals (const std::array< Vec3, 3 > &a_vertexNormals) noexcept
 Set the triangle vertex normals.
 
void setEdgeNormals (const std::array< Vec3, 3 > &a_edgeNormals) noexcept
 Set the triangle edge normals.
 
void setMetaData (const Meta &a_metaData) noexcept
 Set the triangle meta-data.
 
void computeNormal () noexcept
 Compute the triangle normal vector.
 
const Vec3getNormal () const noexcept
 Get the triangle normal vector.
 
const std::array< Vec3, 3 > & getVertexPositions () const noexcept
 Get the vertex positions.
 
const std::array< Vec3, 3 > & getVertexNormals () const noexcept
 Get the vertex normals.
 
const std::array< Vec3, 3 > & getEdgeNormals () const noexcept
 Get the edge normals.
 
const MetagetMetaData () const noexcept
 Get the triangle meta-data.
 
signedDistance (const Vec3 &a_point) const noexcept
 Compute the signed distance from the input point x to the triangle.
 

Protected Attributes

Vec3 m_triangleNormal = Vec3::max()
 Triangle face normal.
 
std::array< Vec3, 3 > m_vertexPositions {Vec3::max(), Vec3::max(), Vec3::max()}
 Triangle vertex positions.
 
std::array< Vec3, 3 > m_vertexNormals {Vec3::max(), Vec3::max(), Vec3::max()}
 Triangle vertex normals.
 
std::array< Vec3, 3 > m_edgeNormals {Vec3::max(), Vec3::max(), Vec3::max()}
 Triangle edge normals.
 
Meta m_metaData
 Triangle meta-data normals.
 

Detailed Description

template<class T, class Meta>
class EBGeometry::Triangle< T, Meta >

Triangle class with signed distance functionality.

This class represents a planar triangle and has a signed distance functionality. It is self-contained: it stores all of its own data and holds no external references. The class contains a triangle face normal vector; three vertex positions, and normal vectors for the three vertices and three edges.

This class assumes that the vertices are organized with the right-hand rule. I.e., edges are enumerated as follows:

Edge 1 points from vertex 1 to vertex 2 Edge 2 points from vertex 2 to vertex 3 Edge 3 points from vertex 3 to vertex 0

This class can compute its own normal vector from the vertex positions, and the triangle orientation is then implicitly given by the vertex order.

To compute the distance from a point to the triangle, one must determine if the point projects to the "inside" or "outside" of the triangle. If the query point projects to the inside of the triangle, the distance is simply the projected distance onto the triangle plane. If it projects to the outside of the triangle, we check the distance against the triangle edges and vertices.

Template Parameters
TFloating-point precision.
MetaUser-defined metadata type stored with the triangle.

Constructor & Destructor Documentation

◆ Triangle() [1/3]

template<class T , class Meta >
EBGeometry::Triangle< T, Meta >::Triangle ( const Triangle< T, Meta > &  a_otherTriangle)
defaultnoexcept

Copy constructor.

Parameters
[in]a_otherTriangleOther triangle.

◆ Triangle() [2/3]

template<class T , class Meta >
EBGeometry::Triangle< T, Meta >::Triangle ( Triangle< T, Meta > &&  a_otherTriangle)
defaultnoexcept

Move constructor.

Parameters
[in,out]a_otherTriangleOther triangle.

◆ Triangle() [3/3]

template<class T , class Meta >
EBGeometry::Triangle< T, Meta >::Triangle ( const std::array< Vec3, 3 > &  a_vertexPositions)
noexcept

Full constructor.

Parameters
[in]a_vertexPositionsTriangle vertex positions.

Member Function Documentation

◆ computeNormal()

template<class T , class Meta >
void EBGeometry::Triangle< T, Meta >::computeNormal ( )
noexcept

Compute the triangle normal vector.

This computes the normal vector from two of the triangle edges, using the right-hand rule and vertex ordering to infer the normal vector. The three vertices must not be collinear (or coincident): a zero-area triangle has an undefined face normal.

◆ getEdgeNormals()

template<class T , class Meta >
const std::array< Vec3, 3 > & EBGeometry::Triangle< T, Meta >::getEdgeNormals ( ) const
noexcept

Get the edge normals.

Const-only; use setEdgeNormals to update.

Returns
m_edgeNormals

◆ getMetaData()

template<class T , class Meta >
const Meta & EBGeometry::Triangle< T, Meta >::getMetaData ( ) const
noexcept

Get the triangle meta-data.

Const-only; use setMetaData to update.

Returns
m_metaData

◆ getNormal()

template<class T , class Meta >
const Vec3 & EBGeometry::Triangle< T, Meta >::getNormal ( ) const
noexcept

Get the triangle normal vector.

Const-only: mutating this in place would desynchronize it from the vertex positions it was derived from. Use setNormal or setVertexPositions instead.

Returns
m_triangleNormal

◆ getVertexNormals()

template<class T , class Meta >
const std::array< Vec3, 3 > & EBGeometry::Triangle< T, Meta >::getVertexNormals ( ) const
noexcept

Get the vertex normals.

Const-only; use setVertexNormals to update.

Returns
m_vertexNormals

◆ getVertexPositions()

template<class T , class Meta >
const std::array< Vec3, 3 > & EBGeometry::Triangle< T, Meta >::getVertexPositions ( ) const
noexcept

Get the vertex positions.

Const-only: mutating positions in place would leave m_triangleNormal stale. Use setVertexPositions instead.

Returns
m_vertexPositions

◆ operator=() [1/2]

template<class T , class Meta >
Triangle & EBGeometry::Triangle< T, Meta >::operator= ( const Triangle< T, Meta > &  a_otherTriangle)
defaultnoexcept

Copy assignment.

Parameters
[in]a_otherTriangleOther triangle.
Returns
Reference to (*this).

◆ operator=() [2/2]

template<class T , class Meta >
Triangle & EBGeometry::Triangle< T, Meta >::operator= ( Triangle< T, Meta > &&  a_otherTriangle)
defaultnoexcept

Move assignment.

Parameters
[in,out]a_otherTriangleOther triangle.
Returns
Reference to (*this).

◆ setEdgeNormals()

template<class T , class Meta >
void EBGeometry::Triangle< T, Meta >::setEdgeNormals ( const std::array< Vec3, 3 > &  a_edgeNormals)
noexcept

Set the triangle edge normals.

Parameters
[in]a_edgeNormalsEdge normals. Each must be finite and unit length.

◆ setMetaData()

template<class T , class Meta >
void EBGeometry::Triangle< T, Meta >::setMetaData ( const Meta a_metaData)
noexcept

Set the triangle meta-data.

Parameters
[in]a_metaDataTriangle metadata.

◆ setNormal()

template<class T , class Meta >
void EBGeometry::Triangle< T, Meta >::setNormal ( const Vec3 a_normal)
noexcept

Set the triangle normal vector.

Parameters
[in]a_normalNormal vector. Must be finite and unit length.
Note
The input normal should be consistent with the vertex ordering.

◆ setVertexNormals()

template<class T , class Meta >
void EBGeometry::Triangle< T, Meta >::setVertexNormals ( const std::array< Vec3, 3 > &  a_vertexNormals)
noexcept

Set the triangle vertex normals.

Parameters
[in]a_vertexNormalsVertex normals. Each must be finite and unit length.

◆ setVertexPositions()

template<class T , class Meta >
void EBGeometry::Triangle< T, Meta >::setVertexPositions ( const std::array< Vec3, 3 > &  a_vertexPositions)
noexcept

Set the triangle vertex positions.

Also recomputes the triangle face normal from the new vertex positions (see computeNormal). The three vertices must not be collinear (or coincident), or the face normal is undefined.

Parameters
[in]a_vertexPositionsVertex positions. Each component must be finite.

◆ signedDistance()

template<class T , class Meta >
T EBGeometry::Triangle< T, Meta >::signedDistance ( const Vec3 a_point) const
noexcept

Compute the signed distance from the input point x to the triangle.

Requires the triangle to be fully initialized with a non-degenerate (non-collinear) set of vertex positions; see setVertexPositions.

Parameters
[in]a_pointQuery point. Must be finite.
Returns
Signed distance; negative inside, positive outside.

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