Thea

Base class for a triangle in 3space, with precomputed properties for fast access. More...
#include <Triangle3.hpp>
Public Types  
typedef VertexTripleT  VertexTriple 
Stores and provides access to the triangle's vertices. More...  
Public Member Functions  
Vector3  barycentricCoordinates (Vector3 const &p) const 
Get the barycentric coordinates of a point assumed to be in the plane of the triangle. More...  
Vector3  closestPoint (Vector3 const &p) const 
Get the point on this triangle closest to a given point. More...  
bool  contains (Vector3 const &p) const 
Check if the triangle contains a point. More...  
Real  distance (Vector3 const &p) const 
Get the distance of the triangle from a point. More...  
template<typename OtherVertexTripleT >  
Real  distance (Triangle3Base< OtherVertexTripleT > const &other) const 
Get the distance of the triangle from another triangle. More...  
Real  distance (Ball3 const &ball) const 
Get the distance of this triangle from a ball. More...  
Real  distance (Line3 const &line) const 
Get the distance of this triangle from an infinite line. More...  
Real  distance (LineSegment3 const &seg) const 
Get the distance of this triangle from a line segment. More...  
Real  distance (Ray3 const &ray) const 
Get the distance of this triangle from a ray. More...  
Real  getArea () const 
Get the area of the triangle. More...  
AxisAlignedBox3  getBounds () const 
Get a bounding box for the triangle. More...  
Vector3 const &  getCentroid () const 
Get the centroid of the triangle. More...  
Vector3 const &  getEdge01 () const 
Get the edge vector corresponding to getVertex(1)  getVertex(0). More...  
Vector3 const &  getEdge02 () const 
Get the edge vector corresponding to getVertex(2)  getVertex(0). More...  
Vector3 const &  getNormal () const 
Get the normal of the triangle (righthand rule, going round vertices in order 0, 1, 2). More...  
Plane3 const &  getPlane () const 
Get the plane of the triangle. More...  
intx  getPrimaryAxis () const 
Get the primary axis of the triangle (closest to normal). More...  
Vector3  getVertex (int i) const 
Get a vertex of the triangle. More...  
VertexTriple const &  getVertices () const 
Get the vertices of the triangle. More...  
bool  intersects (Vector3 const &p) const 
Check if the triangle intersects (that is, contains) a point. More...  
template<typename OtherVertexTripleT >  
bool  intersects (Triangle3Base< OtherVertexTripleT > const &other) const 
Check if the triangle intersects another triangle. More...  
template<typename OtherVertexTripleT >  
bool  intersects (Triangle3Base< OtherVertexTripleT > const &other, bool &coplanar, LineSegment3 &seg) const 
Check if the triangle intersects another triangle. More...  
bool  intersects (Ball3 const &ball) const 
Check if the triangle intersects a ball. More...  
bool  intersects (AxisAlignedBox3 const &aab) const 
Check if the triangle intersects an axisaligned box. More...  
bool  intersects (Box3 const &box) const 
Check if the triangle intersects an oriented box. More...  
Vector3  randomPoint () const 
Get a uniformly distributed random sample from the triangle. More...  
virtual RayIntersectionN< N, T >  rayIntersection (RayN< N, T > const &ray, T max_time=1) const 
Get the intersection of a ray with the object, including the hit time and the normal at the intersection point. More...  
virtual T  rayIntersectionTime (RayN< N, T > const &ray, T max_time=1) const =0 
Get the time taken for a ray to intersect the object, or a negative value if there was no intersection in the forward direction. More...  
virtual bool  rayIntersects (RayN< N, T > const &ray, T max_time=1) const 
Check if a ray intersects the object in the forward direction. More...  
void  set (VertexTriple const &vertices_) 
Initialize the triangle from its vertices. More...  
Real  squaredDistance (Vector3 const &p) const 
Get the squared distance of the triangle from a point. More...  
template<typename OtherVertexTripleT >  
Real  squaredDistance (Triangle3Base< OtherVertexTripleT > const &other, Vector3 *this_pt=nullptr, Vector3 *other_pt=nullptr) const 
Get the squared distance between this triangle and another triangle, and optionally return the closest pair of points. More...  
Real  squaredDistance (Ball3 const &ball, Vector3 *this_pt=nullptr, Vector3 *ball_pt=nullptr) const 
Get the squared distance between this triangle and a ball, and optionally return the closest pair of points. More...  
Real  squaredDistance (Line3 const &line, Vector3 *this_pt=nullptr, Vector3 *line_pt=nullptr) const 
Get the squared distance between this triangle and an infinite line, and optionally return the closest pair of points. More...  
Real  squaredDistance (LineSegment3 const &seg, Vector3 *this_pt=nullptr, Vector3 *seg_pt=nullptr) const 
Get the squared distance between this triangle and a line segment, and optionally return the closest pair of points. More...  
Real  squaredDistance (Ray3 const &ray, Vector3 *this_pt=nullptr, Vector3 *ray_pt=nullptr) const 
Get the squared distance between this triangle and a ray, and optionally return the closest pair of points. More...  
void  update () const 
Update the properties of the triangle, assuming the positions of its three corners have changed. More...  
Protected Member Functions  
template<typename LineLikeT >  
Real  squaredDistanceToPerimeter (LineLikeT const &line, Vector3 *this_pt=nullptr, Vector3 *line_pt=nullptr) const 
Get the squared distance between the perimiter of this triangle and a linelike object (Line3, Ray3 or LineSegment3), and optionally return the closest pair of points. More...  
Triangle3Base ()  
Default constructor. More...  
Triangle3Base (VertexTriple const &vertices_)  
Construct from a set of vertices. More...  
Triangle3Base (Triangle3Base const &src)  
Copy constructor. More...  
Protected Attributes  
Real  area 
Triangle area. More...  
Vector3  centroid 
Centroid of the triangle (mean of three vertices). More...  
Vector3  edge01 
vertices[1]  vertices[0] More...  
Vector3  edge02 
vertices[2]  vertices[0] More...  
Plane3  plane 
Plane of the triangle. More...  
int  primary_axis 
Primary axis (closest to normal). More...  
VertexTriple  vertices 
The vertices of the triangle. More...  
Base class for a triangle in 3space, with precomputed properties for fast access.
To account for the fact that the triangle vertices may be stored in different ways (e.g. internally within the object, or as indices into an external vertex pool), the class is parametrized on the way the vertices are stored. VertexTripleT
must be defaultconstructible and provide an efficient member function with the signature
Definition at line 135 of file Triangle3.hpp.
typedef VertexTripleT VertexTriple 
Stores and provides access to the triangle's vertices.
Definition at line 138 of file Triangle3.hpp.

protected 

explicitprotected 
Construct from a set of vertices.
Definition at line 145 of file Triangle3.hpp.

protected 
Copy constructor.
Definition at line 148 of file Triangle3.hpp.
Vector3 barycentricCoordinates  (  Vector3 const &  p  )  const 
Get the barycentric coordinates of a point assumed to be in the plane of the triangle.
Definition at line 222 of file Triangle3.hpp.
Vector3 closestPoint  (  Vector3 const &  p  )  const 
Get the point on this triangle closest to a given point.
Definition at line 316 of file Triangle3.hpp.
bool contains  (  Vector3 const &  p  )  const 
Check if the triangle contains a point.
Definition at line 301 of file Triangle3.hpp.
Real distance  (  Vector3 const &  p  )  const 
Get the distance of the triangle from a point.
Definition at line 307 of file Triangle3.hpp.
Real distance  (  Triangle3Base< OtherVertexTripleT > const &  other  )  const 
Get the distance of the triangle from another triangle.
Definition at line 329 of file Triangle3.hpp.
Real distance  (  Ball3 const &  ball  )  const 
Get the distance of this triangle from a ball.
Definition at line 421 of file Triangle3.hpp.
Real distance  (  Line3 const &  line  )  const 
Get the distance of this triangle from an infinite line.
Definition at line 464 of file Triangle3.hpp.
Real distance  (  LineSegment3 const &  seg  )  const 
Get the distance of this triangle from a line segment.
Definition at line 507 of file Triangle3.hpp.
Real distance  (  Ray3 const &  ray  )  const 
Get the distance of this triangle from a ray.
Definition at line 533 of file Triangle3.hpp.
Real getArea  (  )  const 
Get the area of the triangle.
Definition at line 200 of file Triangle3.hpp.
AxisAlignedBox3 getBounds  (  )  const 
Get a bounding box for the triangle.
Definition at line 239 of file Triangle3.hpp.
Vector3 const& getCentroid  (  )  const 
Get the centroid of the triangle.
Definition at line 191 of file Triangle3.hpp.
Vector3 const& getEdge01  (  )  const 
Get the edge vector corresponding to getVertex(1)  getVertex(0).
Definition at line 194 of file Triangle3.hpp.
Vector3 const& getEdge02  (  )  const 
Get the edge vector corresponding to getVertex(2)  getVertex(0).
Definition at line 197 of file Triangle3.hpp.
Vector3 const& getNormal  (  )  const 
Get the normal of the triangle (righthand rule, going round vertices in order 0, 1, 2).
Definition at line 188 of file Triangle3.hpp.
Plane3 const& getPlane  (  )  const 
Get the plane of the triangle.
Definition at line 182 of file Triangle3.hpp.
intx getPrimaryAxis  (  )  const 
Get the primary axis of the triangle (closest to normal).
Definition at line 185 of file Triangle3.hpp.
Vector3 getVertex  (  int  i  )  const 
Get a vertex of the triangle.
Definition at line 176 of file Triangle3.hpp.
VertexTriple const& getVertices  (  )  const 
Get the vertices of the triangle.
Definition at line 179 of file Triangle3.hpp.
bool intersects  (  Vector3 const &  p  )  const 
Check if the triangle intersects (that is, contains) a point.
Definition at line 246 of file Triangle3.hpp.
bool intersects  (  Triangle3Base< OtherVertexTripleT > const &  other  )  const 
Check if the triangle intersects another triangle.
Definition at line 249 of file Triangle3.hpp.
bool intersects  (  Triangle3Base< OtherVertexTripleT > const &  other, 
bool &  coplanar,  
LineSegment3 &  seg  
)  const 
Check if the triangle intersects another triangle.
If they do intersect, check if they are coplanar. If they are not coplanar, compute the line of intersection. The intersection test is somewhat slower than intersects().
Definition at line 270 of file Triangle3.hpp.
bool intersects  (  Ball3 const &  ball  )  const 
Check if the triangle intersects a ball.
Definition at line 292 of file Triangle3.hpp.
bool intersects  (  AxisAlignedBox3 const &  aab  )  const 
Check if the triangle intersects an axisaligned box.
Definition at line 295 of file Triangle3.hpp.
bool intersects  (  Box3 const &  box  )  const 
Check if the triangle intersects an oriented box.
Definition at line 298 of file Triangle3.hpp.
Vector3 randomPoint  (  )  const 
Get a uniformly distributed random sample from the triangle.
Definition at line 203 of file Triangle3.hpp.

virtualinherited 
Get the intersection of a ray with the object, including the hit time and the normal at the intersection point.
A negative time is returned if there was no intersection in the forward direction. If the normal cannot be computed, the zero vector is returned.
ray  The ray to test for intersection. 
max_time  Maximum allowable hit time, ignored if negative. 
Reimplemented in AxisAlignedBoxNBase< N, T >, AxisAlignedBoxNBase< 3, T >, BallN< N, T >, HyperplaneNBase< N, T >, HyperplaneNBase< N, Real >, HyperplaneNBase< 3, T >, BoxN< N, T >, and BoxN< 3, Real >.
Definition at line 102 of file RayIntersectableN.hpp.

pure virtualinherited 
Get the time taken for a ray to intersect the object, or a negative value if there was no intersection in the forward direction.
All subclasses must reimplement this method. If the return value is negative, it should be at least
ray  The ray to test for intersection. 
max_time  Maximum allowable hit time, ignored if negative. 
Implemented in AxisAlignedBoxNBase< N, T >, AxisAlignedBoxNBase< 3, T >, HyperplaneNBase< N, T >, HyperplaneNBase< N, Real >, HyperplaneNBase< 3, T >, BallN< N, T >, BoxN< N, T >, and BoxN< 3, Real >.

virtualinherited 
Check if a ray intersects the object in the forward direction.
ray  The ray to test for intersection. 
max_time  Maximum allowable hit time, ignored if negative. 
Reimplemented in AxisAlignedBoxNBase< N, T >, AxisAlignedBoxNBase< 3, T >, HyperplaneNBase< N, T >, HyperplaneNBase< N, Real >, HyperplaneNBase< 3, T >, BallN< N, T >, BoxN< N, T >, and BoxN< 3, Real >.
Definition at line 80 of file RayIntersectableN.hpp.
void set  (  VertexTriple const &  vertices_  ) 
Initialize the triangle from its vertices.
Definition at line 155 of file Triangle3.hpp.
Real squaredDistance  (  Vector3 const &  p  )  const 
Get the squared distance of the triangle from a point.
Definition at line 310 of file Triangle3.hpp.
Real squaredDistance  (  Triangle3Base< OtherVertexTripleT > const &  other, 
Vector3 *  this_pt = nullptr , 

Vector3 *  other_pt = nullptr 

)  const 
Get the squared distance between this triangle and another triangle, and optionally return the closest pair of points.
Definition at line 335 of file Triangle3.hpp.
Real squaredDistance  (  Ball3 const &  ball, 
Vector3 *  this_pt = nullptr , 

Vector3 *  ball_pt = nullptr 

)  const 
Get the squared distance between this triangle and a ball, and optionally return the closest pair of points.
Definition at line 427 of file Triangle3.hpp.
Real squaredDistance  (  Line3 const &  line, 
Vector3 *  this_pt = nullptr , 

Vector3 *  line_pt = nullptr 

)  const 
Get the squared distance between this triangle and an infinite line, and optionally return the closest pair of points.
Definition at line 472 of file Triangle3.hpp.
Real squaredDistance  (  LineSegment3 const &  seg, 
Vector3 *  this_pt = nullptr , 

Vector3 *  seg_pt = nullptr 

)  const 
Get the squared distance between this triangle and a line segment, and optionally return the closest pair of points.
Definition at line 515 of file Triangle3.hpp.
Real squaredDistance  (  Ray3 const &  ray, 
Vector3 *  this_pt = nullptr , 

Vector3 *  ray_pt = nullptr 

)  const 
Get the squared distance between this triangle and a ray, and optionally return the closest pair of points.
Definition at line 541 of file Triangle3.hpp.

protected 
Get the squared distance between the perimiter of this triangle and a linelike object (Line3, Ray3 or LineSegment3), and optionally return the closest pair of points.
Definition at line 581 of file Triangle3.hpp.
void update  (  )  const 
Update the properties of the triangle, assuming the positions of its three corners have changed.
Useful for external callers if the mutable positions are not locally stored within the triangle.
Definition at line 161 of file Triangle3.hpp.

mutableprotected 
Triangle area.
Definition at line 610 of file Triangle3.hpp.

mutableprotected 
Centroid of the triangle (mean of three vertices).
Definition at line 607 of file Triangle3.hpp.

mutableprotected 
vertices[1]  vertices[0]
Definition at line 608 of file Triangle3.hpp.

mutableprotected 
vertices[2]  vertices[0]
Definition at line 609 of file Triangle3.hpp.

mutableprotected 
Plane of the triangle.
Definition at line 605 of file Triangle3.hpp.

mutableprotected 
Primary axis (closest to normal).
Definition at line 606 of file Triangle3.hpp.

protected 
The vertices of the triangle.
Definition at line 602 of file Triangle3.hpp.