AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::primal::Triangle< T, NDIMS > Class Template Reference

Represents a triangular geometric shape defined by three points. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/v0.5.0/src/axom/primal/geometry/Triangle.hpp>

Public Types

enum  { NUM_TRI_VERTS = 3 }
 
typedef Point< T, NDIMS > PointType
 
typedef Vector< T, NDIMS > VectorType
 

Public Member Functions

AXOM_HOST_DEVICE Triangle ()
 Default constructor. Creates a degenerate triangle. More...
 
AXOM_HOST_DEVICE Triangle (const PointType &A, const PointType &B, const PointType &C)
 Custom Constructor. Creates a triangle from the 3 points A,B,C. More...
 
AXOM_HOST_DEVICE ~Triangle ()
 Destructor. More...
 
AXOM_HOST_DEVICE PointTypeoperator[] (int idx)
 Index operator to get the i^th vertex. More...
 
AXOM_HOST_DEVICE const PointTypeoperator[] (int idx) const
 Index operator to get the i^th vertex. More...
 
AXOM_HOST_DEVICE VectorType normal () const
 Returns the normal of the triangle (not normalized) More...
 
AXOM_HOST_DEVICE double area () const
 Returns the area of the triangle. More...
 
Point< double, 3 > physToBarycentric (const PointType &p) const
 Returns the barycentric coordinates of a point within a triangle. More...
 
PointType baryToPhysical (const Point< double, 3 > &bary) const
 Returns the physical coordinates of a barycentric point. More...
 
AXOM_HOST_DEVICE bool degenerate (double eps=1.0e-12) const
 Returns whether the triangle is degenerate. More...
 
bool checkInTriangle (const PointType &p, double eps=1.0e-8) const
 Returns whether Point P is in the triangle for some 3d Triangle. More...
 
double angle (int idx) const
 Computes the request angle corresponding to the given vertex ID. More...
 
std::ostream & print (std::ostream &os) const
 Simple formatted print of a triangle instance. More...
 

Detailed Description

template<typename T, int NDIMS>
class axom::primal::Triangle< T, NDIMS >

Represents a triangular geometric shape defined by three points.

Template Parameters
Tthe coordinate type, e.g., double, float, etc.
NDIMSthe number of dimensions

Member Typedef Documentation

◆ PointType

template<typename T, int NDIMS>
typedef Point<T, NDIMS> axom::primal::Triangle< T, NDIMS >::PointType

◆ VectorType

template<typename T, int NDIMS>
typedef Vector<T, NDIMS> axom::primal::Triangle< T, NDIMS >::VectorType

Member Enumeration Documentation

◆ anonymous enum

template<typename T, int NDIMS>
anonymous enum
Enumerator
NUM_TRI_VERTS 

Constructor & Destructor Documentation

◆ Triangle() [1/2]

template<typename T , int NDIMS>
axom::primal::Triangle< T, NDIMS >::Triangle ( )

Default constructor. Creates a degenerate triangle.

◆ Triangle() [2/2]

template<typename T , int NDIMS>
axom::primal::Triangle< T, NDIMS >::Triangle ( const PointType A,
const PointType B,
const PointType C 
)

Custom Constructor. Creates a triangle from the 3 points A,B,C.

Parameters
[in]Apoint instance corresponding to vertex A of the triangle.
[in]Bpoint instance corresponding to vertex B of the triangle.
[in]Cpoint instance corresponding to vertex C of the triangle.

References A, and B.

◆ ~Triangle()

template<typename T, int NDIMS>
AXOM_HOST_DEVICE axom::primal::Triangle< T, NDIMS >::~Triangle ( )
inline

Destructor.

References AXOM_HOST_DEVICE.

Member Function Documentation

◆ operator[]() [1/2]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE PointType& axom::primal::Triangle< T, NDIMS >::operator[] ( int  idx)
inline

Index operator to get the i^th vertex.

Parameters
idxThe index of the desired vertex
Precondition
idx is 0, 1 or 2

References AXOM_HOST_DEVICE, axom::primal::Triangle< T, NDIMS >::NUM_TRI_VERTS, and SLIC_ASSERT.

◆ operator[]() [2/2]

template<typename T, int NDIMS>
AXOM_HOST_DEVICE const PointType& axom::primal::Triangle< T, NDIMS >::operator[] ( int  idx) const
inline

Index operator to get the i^th vertex.

Parameters
idxThe index of the desired vertex
Precondition
idx is 0, 1 or 2

References AXOM_HOST_DEVICE, axom::primal::Triangle< T, NDIMS >::NUM_TRI_VERTS, and SLIC_ASSERT.

◆ normal()

template<typename T, int NDIMS>
AXOM_HOST_DEVICE VectorType axom::primal::Triangle< T, NDIMS >::normal ( ) const
inline

Returns the normal of the triangle (not normalized)

Precondition
This function is only valid when NDIMS = 3
Returns
n triangle normal when NDIMS=3, zero vector otherwise

References AXOM_HOST_DEVICE, axom::primal::Vector< T, NDIMS >::cross_product(), and SLIC_CHECK_MSG.

◆ area()

template<typename T, int NDIMS>
AXOM_HOST_DEVICE double axom::primal::Triangle< T, NDIMS >::area ( ) const
inline

Returns the area of the triangle.

Precondition
Only defined when dimension NDIMS is 2 or 3

References A, B, C, axom::primal::Vector< T, NDIMS >::cross_product(), and SLIC_CHECK_MSG.

Referenced by axom::primal::Triangle< T, NDIMS >::degenerate().

◆ physToBarycentric()

template<typename T, int NDIMS>
Point<double, 3> axom::primal::Triangle< T, NDIMS >::physToBarycentric ( const PointType p) const
inline

Returns the barycentric coordinates of a point within a triangle.

Returns
The barycentric coordinates of the triangle inside a Point<T,3>
Precondition
The point lies in this triangle's plane.
Postcondition
The barycentric coordinates sum to 1. Adapted from Real Time Collision Detection by Christer Ericson.

References A, axom::utilities::abs(), B, C, axom::primal::Vector< T, NDIMS >::cross_product(), axom::numerics::determinant(), axom::utilities::isNearlyEqual(), and SLIC_CHECK.

Referenced by axom::primal::Triangle< T, NDIMS >::checkInTriangle().

◆ baryToPhysical()

template<typename T, int NDIMS>
PointType axom::primal::Triangle< T, NDIMS >::baryToPhysical ( const Point< double, 3 > &  bary) const
inline

Returns the physical coordinates of a barycentric point.

Parameters
[in]baryBarycentric coordinates relative to this triangle
Returns
Physical point represented by bary

References AXOM_HOST_DEVICE, axom::utilities::isNearlyEqual(), and SLIC_CHECK_MSG.

◆ degenerate()

template<typename T, int NDIMS>
AXOM_HOST_DEVICE bool axom::primal::Triangle< T, NDIMS >::degenerate ( double  eps = 1.0e-12) const
inline

Returns whether the triangle is degenerate.

Returns
true iff the triangle is degenerate (0 area)
See also
primal::Point

References axom::primal::Triangle< T, NDIMS >::area(), and axom::utilities::isNearlyEqual().

Referenced by axom::quest::getMeshTriangle().

◆ checkInTriangle()

template<typename T, int NDIMS>
bool axom::primal::Triangle< T, NDIMS >::checkInTriangle ( const PointType p,
double  eps = 1.0e-8 
) const
inline

Returns whether Point P is in the triangle for some 3d Triangle.

Returns
true iff P is in the triangle
See also
primal::Point

References axom::primal::Triangle< T, NDIMS >::angle(), axom::utilities::isNearlyEqual(), and axom::primal::Triangle< T, NDIMS >::physToBarycentric().

◆ angle()

template<typename T , int NDIMS>
double axom::primal::Triangle< T, NDIMS >::angle ( int  idx) const
inline

Computes the request angle corresponding to the given vertex ID.

Parameters
[in]idxthe index of the corresponding vertex
Returns
alpha the incidence angle in the range [0, pi].
Precondition
idx >= 0 && idx < NUM_TRI_VERTS

References axom::primal::Vector< T, NDIMS >::dot_product(), axom::primal::Vector< T, NDIMS >::norm(), axom::primal::Triangle< T, NDIMS >::NUM_TRI_VERTS, and SLIC_ASSERT.

Referenced by axom::primal::Triangle< T, NDIMS >::checkInTriangle().

◆ print()

template<typename T, int NDIMS>
std::ostream& axom::primal::Triangle< T, NDIMS >::print ( std::ostream &  os) const
inline

Simple formatted print of a triangle instance.

Parameters
osThe output stream to write to
Returns
A reference to the modified ostream

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