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

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

#include <triangle_2d.h>

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

Public Member Functions

 Triangle2D ()
 constructs an empty triangle.
 
 Triangle2D (const TPoint &iA, const TPoint &iB, const TPoint &iC)
 Constructs a triangle through three points in positive sequence.
 
const TPoint & operator[] (size_t iIndexOfVertex) const
 return vertex of polygon by its index, not wrapped, no bounds check.
 
TPoint & operator[] (size_t iIndexOfVertex)
 return vertex of polygon by its index, not wrapped, no bounds check.
 
const TPoint & at (int iIndexOfVertex) const
 return vertex of polygon by its index, but wrap around the bounds.
 
TPoint & at (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)\
 
bool isEmpty () const
 return true if polygon has no vertices
 
int size () const
 return number of vertices
 
const TValue signedArea () const
 return signed polygon area.
 
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 barycenter of all vertices.
 
bool isSimple () const
 return true if polygon is simple, false if not.
 
bool isConvex () const
 return true if polygon is convex, false if not.
 
Orientation orientation () const
 return orientation of polygon.
 
bool isReflex (int iIndexOfVertex) const
 return true if inner angle of vertex is reflex (is > 180 degrees).
 
bool contains (const TPoint &iP) const
 return true when a point is inside or on the edge of a triangle.
 
void flip ()
 flip orientation of polygon.
 

Related Symbols

(Note that these are not member symbols.)

template<typename T>
Aabb2D< T > aabb (const Triangle2D< T > &triangle)
 determine axis aligned bounding box of a 2D triangle
 
template<typename T, class NP, class PP>
Result intersect (const Triangle2D< T > &triangle, const Ray2D< 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>
partialVoronoiArea (const Triangle2D< T > iT, int vertexIndex)
 Returns the surface of the partial Voronoi cell constructed around vertex vertexIndex (say vertex a in triangle abc).
 

Detailed Description

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

A very simple 2D polygon :)

Author
Bram de Greve [BdG]

Definition at line 64 of file triangle_2d.h.

Constructor & Destructor Documentation

◆ Triangle2D()

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

constructs an empty triangle.

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

Definition at line 61 of file triangle_2d.inl.

Member Function Documentation

◆ operator[]() [1/2]

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

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

Definition at line 82 of file triangle_2d.inl.

◆ operator[]() [2/2]

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

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

Definition at line 93 of file triangle_2d.inl.

◆ at() [1/2]

template<typename T>
const Triangle2D< T >::TPoint & lass::prim::Triangle2D< T >::at ( int vertexIndex) 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);

Exceptions
anexception is thrown if polygon is empty

Definition at line 104 of file triangle_2d.inl.

Referenced by edge(), lass::prim::Triangle2D< U >::partialVoronoiArea(), and vector().

◆ at() [2/2]

template<typename T>
Triangle2D< T >::TPoint & lass::prim::Triangle2D< T >::at ( int vertexIndex)

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);

Exceptions
anexception is thrown if polygon is empty

Definition at line 116 of file triangle_2d.inl.

◆ edge()

template<typename T>
const Triangle2D< T >::TLineSegment lass::prim::Triangle2D< T >::edge ( int tailVertexIndex) const

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

Exceptions
anexception is thrown if polygon has less than two vertices

Definition at line 128 of file triangle_2d.inl.

References at().

◆ vector()

template<typename T>
const Triangle2D< T >::TVector lass::prim::Triangle2D< T >::vector ( int tailVertexIndex) const

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

Definition at line 138 of file triangle_2d.inl.

References at().

◆ isEmpty()

template<typename T>
bool lass::prim::Triangle2D< 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 150 of file triangle_2d.inl.

◆ size()

template<typename T>
int lass::prim::Triangle2D< T >::size ( ) const

return number of vertices

Definition at line 160 of file triangle_2d.inl.

◆ signedArea()

template<typename T>
const Triangle2D< T >::TValue lass::prim::Triangle2D< T >::signedArea ( ) const

return signed polygon area.

The area of a convex polygon is defined to be positive if the points are arranged in a counterclockwise order, and negative if they are in clockwise order., Eric W. Weisstein. "Polygon Area." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/PolygonArea.html

Algorithm:
comp.graphics.algorithms Frequently Asked Questions: Subject 2.01: "How do I find the area of a polygon?" http://www.faqs.org/faqs/graphics/algorithms-faq/

https://www.johndcook.com/blog/2018/09/26/polygon-area/

Warning
polygon must be simple accoring degenerate policy.

Definition at line 170 of file triangle_2d.inl.

Referenced by area(), and orientation().

◆ area()

template<typename T>
const Triangle2D< T >::TValue lass::prim::Triangle2D< 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

Warning
polygon must be simple accoring DegeneratePolicy.

Definition at line 181 of file triangle_2d.inl.

References lass::num::abs(), and signedArea().

Referenced by orientation(), and lass::prim::Triangle2D< U >::partialVoronoiArea().

◆ perimeter()

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

return sum of the lengths of all edges

Definition at line 191 of file triangle_2d.inl.

◆ vertexCentroid()

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

return the barycenter of all vertices.

The vertex centroid 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 204 of file triangle_2d.inl.

Referenced by surfaceCentroid().

◆ surfaceCentroid()

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

return the barycenter of all vertices.

The vertex centroid 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 216 of file triangle_2d.inl.

References vertexCentroid().

◆ isSimple()

template<typename T>
bool lass::prim::Triangle2D< 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

A polygon with less than four vertices is always 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 always is simple

Definition at line 228 of file triangle_2d.inl.

◆ isConvex()

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

return true if polygon is convex, false if not.

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 cross products of colinear edges, 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 coincident. vertices is considered convex if DegeneratePolicy allows this.

Warning
polygon must be simple and should not have coincident vertices, according DegeneratePolicy.
Triangle specific:
A triangle always is convex

Definition at line 240 of file triangle_2d.inl.

◆ orientation()

template<typename T>
Orientation lass::prim::Triangle2D< T >::orientation ( ) const

return orientation of polygon.

Warning
polygon must be simple accoring DegeneratePolicy.

Definition at line 250 of file triangle_2d.inl.

References area(), lass::prim::oClockWise, lass::prim::oCounterClockWise, lass::prim::oInvalid, and signedArea().

◆ isReflex()

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

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

Reflect Angle: An angle more than 180�, Eric W. Weisstein. "Reflex Angle." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/ReflexAngle.html

test if signedArea() and perdDot(...) have different sign. if one of them is zero, it will return false by default.

Warning
polygon must be simple accoring DegeneratePolicy.
Triangle specific:
triangles never have reflex vertices, so always returns false.

Definition at line 274 of file triangle_2d.inl.

Friends And Related Symbol Documentation

◆ aabb()

template<typename T>
Aabb2D< T > aabb ( const Triangle2D< T > & triangle)
related

determine axis aligned bounding box of a 2D triangle

See also
lass::prim::Aabb2D

Definition at line 60 of file aabb_2d_triangle_2d.h.

◆ intersect()

template<typename T, class NP, class PP>
Result intersect ( const Triangle2D< T > & triangle,
const Ray2D< 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.

Definition at line 72 of file ray_2d_triangle_2d.h.

◆ partialVoronoiArea()

template<typename T>
T partialVoronoiArea ( const Triangle2D< T > iT,
int vertexIndex )
related

Returns the surface of the partial Voronoi cell constructed around vertex vertexIndex (say vertex a in triangle abc).

Then the surface is determined by the quad built by a, the two midpoints on ab and ac and the intersection of the two perpendicular bisectors.

Definition at line 468 of file triangle_2d.inl.


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