Thea
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Triangle3< VertexTripleT > Class Template Referenceabstract

A triangle in 3-space, with precomputed properties for fast access. More...

#include <Triangle3.hpp>

Inheritance diagram for Triangle3< VertexTripleT >:
Triangle3Base< VertexTripleT > RayIntersectableN< N, T >

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 (right-hand 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 axis-aligned box. More...
 
bool intersects (Box3 const &box) const
 Check if the triangle intersects an oriented box. More...
 
LocalTriangle3 localClone () const
 Get a new triangle that simply stores copies of the vertex positions of this triangle. 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...
 
LocalTriangle3 transform (Matrix4 const &m) const
 Transform the triangle by a 4x4 matrix and return the result. More...
 
 Triangle3 ()
 Default constructor. More...
 
 Triangle3 (VertexTripleT const &vertices_)
 Construct from a set of vertices. More...
 
 Triangle3 (Triangle3 const &src)
 Copy constructor. 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 line-like object (Line3, Ray3 or LineSegment3), and optionally return the closest pair of points. 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...
 

Detailed Description

template<typename VertexTripleT>
class Thea::Triangle3< VertexTripleT >

A triangle in 3-space, 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 default-constructible and provide an efficient member function with the signature

Vector3 const & getVertex(int i) const

Definition at line 615 of file Triangle3.hpp.

Member Typedef Documentation

typedef VertexTripleT VertexTriple
inherited

Stores and provides access to the triangle's vertices.

Definition at line 138 of file Triangle3.hpp.

Constructor & Destructor Documentation

Triangle3 ( )

Default constructor.

Does not initialize anything.

Definition at line 687 of file Triangle3.hpp.

Triangle3 ( VertexTripleT const &  vertices_)
explicit

Construct from a set of vertices.

Definition at line 690 of file Triangle3.hpp.

Triangle3 ( Triangle3< VertexTripleT > const &  src)

Copy constructor.

Definition at line 693 of file Triangle3.hpp.

Member Function Documentation

Vector3 barycentricCoordinates ( Vector3 const &  p) const
inherited

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
inherited

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
inherited

Check if the triangle contains a point.

Definition at line 301 of file Triangle3.hpp.

Real distance ( Vector3 const &  p) const
inherited

Get the distance of the triangle from a point.

Definition at line 307 of file Triangle3.hpp.

Real distance ( Triangle3Base< OtherVertexTripleT > const &  other) const
inherited

Get the distance of the triangle from another triangle.

Definition at line 329 of file Triangle3.hpp.

Real distance ( Ball3 const &  ball) const
inherited

Get the distance of this triangle from a ball.

Definition at line 421 of file Triangle3.hpp.

Real distance ( Line3 const &  line) const
inherited

Get the distance of this triangle from an infinite line.

Definition at line 464 of file Triangle3.hpp.

Real distance ( LineSegment3 const &  seg) const
inherited

Get the distance of this triangle from a line segment.

Definition at line 507 of file Triangle3.hpp.

Real distance ( Ray3 const &  ray) const
inherited

Get the distance of this triangle from a ray.

Definition at line 533 of file Triangle3.hpp.

Real getArea ( ) const
inherited

Get the area of the triangle.

Definition at line 200 of file Triangle3.hpp.

AxisAlignedBox3 getBounds ( ) const
inherited

Get a bounding box for the triangle.

Definition at line 239 of file Triangle3.hpp.

Vector3 const& getCentroid ( ) const
inherited

Get the centroid of the triangle.

Definition at line 191 of file Triangle3.hpp.

Vector3 const& getEdge01 ( ) const
inherited

Get the edge vector corresponding to getVertex(1) - getVertex(0).

Definition at line 194 of file Triangle3.hpp.

Vector3 const& getEdge02 ( ) const
inherited

Get the edge vector corresponding to getVertex(2) - getVertex(0).

Definition at line 197 of file Triangle3.hpp.

Vector3 const& getNormal ( ) const
inherited

Get the normal of the triangle (right-hand rule, going round vertices in order 0, 1, 2).

Definition at line 188 of file Triangle3.hpp.

Plane3 const& getPlane ( ) const
inherited

Get the plane of the triangle.

Definition at line 182 of file Triangle3.hpp.

intx getPrimaryAxis ( ) const
inherited

Get the primary axis of the triangle (closest to normal).

Definition at line 185 of file Triangle3.hpp.

Vector3 getVertex ( int  i) const
inherited

Get a vertex of the triangle.

Definition at line 176 of file Triangle3.hpp.

VertexTriple const& getVertices ( ) const
inherited

Get the vertices of the triangle.

Definition at line 179 of file Triangle3.hpp.

bool intersects ( Vector3 const &  p) const
inherited

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
inherited

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
inherited

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
inherited

Check if the triangle intersects a ball.

Definition at line 292 of file Triangle3.hpp.

bool intersects ( AxisAlignedBox3 const &  aab) const
inherited

Check if the triangle intersects an axis-aligned box.

Definition at line 295 of file Triangle3.hpp.

bool intersects ( Box3 const &  box) const
inherited

Check if the triangle intersects an oriented box.

Definition at line 298 of file Triangle3.hpp.

LocalTriangle3 localClone ( ) const

Get a new triangle that simply stores copies of the vertex positions of this triangle.

Definition at line 702 of file Triangle3.hpp.

Vector3 randomPoint ( ) const
inherited

Get a uniformly distributed random sample from the triangle.

Definition at line 203 of file Triangle3.hpp.

virtual RayIntersectionN<N, T> rayIntersection ( RayN< N, T > const &  ray,
max_time = -1 
) const
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.

Parameters
rayThe ray to test for intersection.
max_timeMaximum allowable hit time, ignored if negative.
Note
The returned normal need not have unit length.

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.

virtual T rayIntersectionTime ( RayN< N, T > const &  ray,
max_time = -1 
) const
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

Parameters
rayThe ray to test for intersection.
max_timeMaximum 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 >.

virtual bool rayIntersects ( RayN< N, T > const &  ray,
max_time = -1 
) const
virtualinherited

Check if a ray intersects the object in the forward direction.

Parameters
rayThe ray to test for intersection.
max_timeMaximum 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_)
inherited

Initialize the triangle from its vertices.

Definition at line 155 of file Triangle3.hpp.

Real squaredDistance ( Vector3 const &  p) const
inherited

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
inherited

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
inherited

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
inherited

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
inherited

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
inherited

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.

Real squaredDistanceToPerimeter ( LineLikeT const &  line,
Vector3 *  this_pt = nullptr,
Vector3 *  line_pt = nullptr 
) const
protectedinherited

Get the squared distance between the perimiter of this triangle and a line-like object (Line3, Ray3 or LineSegment3), and optionally return the closest pair of points.

Definition at line 581 of file Triangle3.hpp.

LocalTriangle3 transform ( Matrix4 const &  m) const

Transform the triangle by a 4x4 matrix and return the result.

Definition at line 696 of file Triangle3.hpp.

void update ( ) const
inherited

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.

Member Data Documentation

Real area
mutableprotectedinherited

Triangle area.

Definition at line 610 of file Triangle3.hpp.

Vector3 centroid
mutableprotectedinherited

Centroid of the triangle (mean of three vertices).

Definition at line 607 of file Triangle3.hpp.

Vector3 edge01
mutableprotectedinherited

vertices[1] - vertices[0]

Definition at line 608 of file Triangle3.hpp.

Vector3 edge02
mutableprotectedinherited

vertices[2] - vertices[0]

Definition at line 609 of file Triangle3.hpp.

Plane3 plane
mutableprotectedinherited

Plane of the triangle.

Definition at line 605 of file Triangle3.hpp.

int primary_axis
mutableprotectedinherited

Primary axis (closest to normal).

Definition at line 606 of file Triangle3.hpp.

VertexTriple vertices
protectedinherited

The vertices of the triangle.

Definition at line 602 of file Triangle3.hpp.


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