Library of Assembled Shared Sources
lass::prim::Triangle3D< T > Class Template Reference

A very simple 3D polygon :) More...

#include <triangle_3d.h>

Inheritance diagram for lass::prim::Triangle3D< T >:

Public Member Functions

 Triangle3D ()
 constructs an empty triangle.
 
 Triangle3D (const TPoint &iA, const TPoint &iB, const TPoint &iC)
 Constructs a triangle through three points in positive sequence.
 
const TPointoperator[] (size_t iIndexOfVertex) const
 return vertex of polygon by its index, not wrapped, no bounds check.
 
TPointoperator[] (size_t iIndexOfVertex)
 return vertex of polygon by its index, not wrapped, no bounds check.
 
const TPointat (int iIndexOfVertex) const
 return vertex of polygon by its index, but wrap around the bounds.
 
TPointat (int iIndexOfVertex)
 return vertex of polygon by its index, but wrap around the bounds.
 
const TLineSegment edge (int iIndexOfTailVertex) const
 return the edge of the polygon between vertices at(iIndex) and at(iIndex + 1).
 
const TVector vector (int iIndexOfTailVertex) const
 return the vector between vertices at(iIndex) and at(iIndex + 1)\
 
const TPlane plane () const
 return support plane of polygon.
 
bool isEmpty () const
 return true if polygon has no vertices
 
size_t size () const
 return number of vertices
 
const TValue squaredArea () const
 returns squared area of triangle to avoid the square root.
 
const TValue area () const
 return area of the polygons surface.
 
const TValue perimeter () const
 return sum of the lengths of all edges
 
const TPointH vertexCentroid () const
 return the barycenter of all vertices.
 
const TPointH surfaceCentroid () const
 return the centroid of the filled polygon.
 
bool isSimple () const
 return true if polygon is simple, false if not.
 
bool isConvex () const
 return true if polygon is convex, false if not.
 
bool isReflex (int iIndexOfVertex) const
 return true if inner angle of vertex is reflex (is > 180 degrees).
 

Related Symbols

(Note that these are not member symbols.)

template<typename T, class NP, class PP>
Result intersect (const Triangle3D< T > &triangle, const Ray3D< T, NP, PP > &ray, T &t, const T &tMin=T())
 Find the intersection of a ray and a triangle by their parameter t on the ray.
 
template<typename T, class NP, class PP>
Result intersect (const Triangle3D< T > &triangle, const Ray3D< T, NP, PP > &ray, T &u, T &v, T &t, const T &tMin=T())
 Find the intersection of a ray and a triangle by their parameter t on the ray and it's coordinates (u,v) on the triangle.
 

Detailed Description

template<typename T>
class lass::prim::Triangle3D< T >

A very simple 3D polygon :)

Author
Bram de Greve [BdG]

Definition at line 63 of file triangle_3d.h.

Constructor & Destructor Documentation

◆ Triangle3D()

template<typename T>
lass::prim::Triangle3D< T >::Triangle3D ( )

constructs an empty triangle.

all vertices are (0, 0) and thus equal.

Definition at line 60 of file triangle_3d.inl.

Member Function Documentation

◆ operator[]() [1/2]

template<typename T>
const Triangle3D< T >::TPoint & lass::prim::Triangle3D< T >::operator[] ( size_t iIndexOfVertex) const

return vertex of polygon by its index, not wrapped, no bounds check.

Definition at line 82 of file triangle_3d.inl.

◆ operator[]() [2/2]

template<typename T>
Triangle3D< T >::TPoint & lass::prim::Triangle3D< T >::operator[] ( size_t iIndexOfVertex)

return vertex of polygon by its index, not wrapped, no bounds check.

Definition at line 94 of file triangle_3d.inl.

◆ at() [1/2]

template<typename T>
const Triangle3D< T >::TPoint & lass::prim::Triangle3D< T >::at ( int iIndexOfVertex) const

return vertex of polygon by its index, but wrap around the bounds.

this->at(-1) will return the same vertex as this->at(this->size() - 1);

Definition at line 106 of file triangle_3d.inl.

Referenced by edge(), and vector().

◆ at() [2/2]

template<typename T>
Triangle3D< T >::TPoint & lass::prim::Triangle3D< T >::at ( int iIndexOfVertex)

return vertex of polygon by its index, but wrap around the bounds.

this->at(-1) will return the same vertex as this->at(this->size() - 1);

Definition at line 119 of file triangle_3d.inl.

◆ edge()

template<typename T>
const Triangle3D< T >::TLineSegment lass::prim::Triangle3D< T >::edge ( int iIndexOfTailVertex) const

return the edge of the polygon between vertices at(iIndex) and at(iIndex + 1).

Definition at line 132 of file triangle_3d.inl.

References at().

◆ vector()

template<typename T>
const Triangle3D< T >::TVector lass::prim::Triangle3D< T >::vector ( int iIndexOfTailVertex) const

return the vector between vertices at(iIndex) and at(iIndex + 1)\

Definition at line 143 of file triangle_3d.inl.

References at().

◆ plane()

template<typename T>
const Triangle3D< T >::TPlane lass::prim::Triangle3D< T >::plane ( ) const

return support plane of polygon.

Definition at line 154 of file triangle_3d.inl.

◆ isEmpty()

template<typename T>
bool lass::prim::Triangle3D< T >::isEmpty ( ) const

return true if polygon has no vertices

Triangle specific:
if all vertices are equal, we assume the triangle is empty

Definition at line 166 of file triangle_3d.inl.

◆ size()

template<typename T>
size_t lass::prim::Triangle3D< T >::size ( ) const

return number of vertices

Definition at line 176 of file triangle_3d.inl.

◆ squaredArea()

template<typename T>
const Triangle3D< T >::TValue lass::prim::Triangle3D< T >::squaredArea ( ) const

returns squared area of triangle to avoid the square root.

Returns
num::sqr(area()) but faster :)

Definition at line 188 of file triangle_3d.inl.

Referenced by area().

◆ area()

template<typename T>
const Triangle3D< T >::TValue lass::prim::Triangle3D< T >::area ( ) const

return area of the polygons surface.

The area of a surface is the amount of material needed to "cover" it completely, Eric W. Weisstein. "Area." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/Area.html

Definition at line 200 of file triangle_3d.inl.

References squaredArea().

◆ perimeter()

template<typename T>
const Triangle3D< T >::TValue lass::prim::Triangle3D< T >::perimeter ( ) const

return sum of the lengths of all edges

Definition at line 211 of file triangle_3d.inl.

◆ vertexCentroid()

template<typename T>
const Triangle3D< T >::TPointH lass::prim::Triangle3D< T >::vertexCentroid ( ) const

return the barycenter of all vertices.

The barycenter is the homogenous sum of all vertices.

Warning
for non-convex polygons, it's NOT guaranteed that this center is inside the polygon.

Definition at line 224 of file triangle_3d.inl.

Referenced by surfaceCentroid().

◆ surfaceCentroid()

template<typename T>
const Triangle3D< T >::TPointH lass::prim::Triangle3D< T >::surfaceCentroid ( ) const
inline

return the centroid of the filled polygon.

Eric W. Weisstein. "Geometric Centroid." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/GeometricCentroid.html

Algorithm:
comp.graphics.algorithms Frequently Asked Questions: Subject 2.02: "How can the centroid of a polygon be computed?" http://www.faqs.org/faqs/graphics/algorithms-faq/
Warning
for non-convex polygons, it's NOT guaranteed that this center is inside the polygon.

Definition at line 236 of file triangle_3d.inl.

References vertexCentroid().

◆ isSimple()

template<typename T>
bool lass::prim::Triangle3D< T >::isSimple ( ) const

return true if polygon is simple, false if not.

A polygon P is said to be simple (or Jordan) if the only points of the plane belonging to two polygon edges of P are the polygon vertices of P. Such a polygon has a well defined interior and exterior. Simple polygons are topologically equivalent to a disk., Eric W. Weisstein. "Simple Polygon." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/SimplePolygon.html

In 3D, we test if the 2D mapping on the major axis is simple.

Warning
this is a brute force test. we simple test for all edges if they are not intersecting Hence, this is O(n^2).
Triangle specific:
A triangle is always simple

Definition at line 248 of file triangle_3d.inl.

◆ isConvex()

template<typename T>
bool lass::prim::Triangle3D< T >::isConvex ( ) const

return true if polygon is convex, false if not.

Warning
assumes polygon is simple

A planar polygon is convex if it contains all the line segments connecting any pair of its points. Thus, for example, a regular pentagon is convex, while an indented pentagon is not. A planar polygon that is not convex is said to be a concave polygon, Eric W. Weisstein. "Convex Polygon." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/ConvexPolygon.html

A simple polygon is convex if all the cross products of adjacent edges will be the same sign (we ignore zero signs, only + or - are taken in account), a concave polygon will have a mixture of cross product signs.

A polygon with less than three vertices is always convex. A polygon with all colinear vertices is considered convex (not very usefull maybe, but convex).

Triangle specific:
A triangle is always convex

Definition at line 260 of file triangle_3d.inl.

◆ isReflex()

template<typename T>
bool lass::prim::Triangle3D< T >::isReflex ( int iIndexOfVertex) const

return true if inner angle of vertex is reflex (is > 180 degrees).

Warning
assumes polygon is simple
Triangle specific:
A triangle never has reflex vertices

Definition at line 272 of file triangle_3d.inl.

Friends And Related Symbol Documentation

◆ intersect() [1/2]

template<typename T, class NP, class PP>
Result intersect ( const Triangle3D< T > & triangle,
const Ray3D< T, NP, PP > & ray,
T & t,
const T & tMin = T() )
related

Find the intersection of a ray and a triangle by their parameter t on the ray.

A maximum of two possible intersections with t > 0.

Parameters
triangle[in] the triangle
ray[in] the ray
t[out] the parameter of the intersection point > tMin.
tMin[in] the minimum t that may be returned as valid intersection.
Returns
  • rNone no intersections with t > tMin found t is not assigned.
  • rOne a intersection with t > tMin is found t is assigned.
Note
MOLLER T. and TRUMBORE B. <q>Fast, Minimum Storage Ray/Triangle Intersection</q>, Journal of Graphics Tools, 2(1), 21-28 (1997). http://www.graphics.cornell.edu/pubs/1997/MT97.html

Definition at line 76 of file ray_3d_triangle_3d.h.

◆ intersect() [2/2]

template<typename T, class NP, class PP>
Result intersect ( const Triangle3D< T > & triangle,
const Ray3D< T, NP, PP > & ray,
T & u,
T & v,
T & t,
const T & tMin = T() )
related

Find the intersection of a ray and a triangle by their parameter t on the ray and it's coordinates (u,v) on the triangle.

A maximum of two possible intersections with t > 0.

Parameters
triangle[in] the triangle
ray[in] the ray
u[out] the parameter of the intersection point on the triangle.
v[out] the parameter of the intersection point on the triangle.
t[out] the parameter of the intersection point > tMin.
tMin[in] the minimum t that may be returned as valid intersection.
Returns
  • rNone no intersections with t > tMin found t is not assigned.
  • rOne a intersection with t > tMin is found t is assigned.
Note
MOLLER T. and TRUMBORE B. <q>Fast, Minimum Storage Ray/Triangle Intersection</q>, Journal of Graphics Tools, 2(1), 21-28 (1997). http://www.graphics.cornell.edu/pubs/1997/MT97.html

Definition at line 113 of file ray_3d_triangle_3d.h.


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