library of assembled shared sources

http://lass.cocamware.com

lass::prim::Triangle2D< T > Class Template Reference

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

#include <triangle_2d.h>


Data Structures

struct  Rebind

Public Types

enum  { dimension = TPoint::dimension }
typedef Triangle2D< T > TSelf
typedef Point2D< T > TPoint
typedef Point2DH< T > TPointH
typedef TPoint::TVector TVector
typedef LineSegment2D< T > TLineSegment
typedef TPoint::TValue TValue
typedef TPoint::TParam TParam
typedef TPoint::TReference TReference
typedef TPoint::TConstReference TConstReference
typedef TPoint::TNumTraits TNumTraits

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 TPointoperator[] (int iIndexOfVertex) const
TPointoperator[] (int iIndexOfVertex)
const TPointat (int iIndexOfVertex) const
TPointat (int iIndexOfVertex)
const TLineSegment edge (int iIndexOfTailVertex) const
const TVector vector (int iIndexOfTailVertex) const
const bool isEmpty () const
const int size () const
const TValue signedArea () const
const TValue area () const
const TValue perimeter () const
const TPointH vertexCentroid () const
const TPointH surfaceCentroid () const
const bool isSimple () const
const bool isConvex () const
const bool isConcave () const
const Orientation orientation () const
const bool isReflex (int iIndexOfVertex) const
const Side classify (const TPoint &iP) const
const 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.

Private Types

enum  { size_ = 3 }

Private Member Functions

const bool isInRange (int iIndexOfVertex) const
 return if index of vertex is in range of the std::vector

Private Attributes

TPoint vertices_ [size_]

Related Functions

(Note that these are not member functions.)

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 >
const T squaredDistance (const Triangle2D< T > &triangle, const Point2D< T > &point)
template<typename T >
const T distance (const Triangle2D< T > &triangle, const Point2D< T > &point)
template<typename T >
io::XmlOStreamoperator<< (io::XmlOStream &ioOStream, const Triangle2D< T > &iTriangle)
template<typename T >
std::ostream & operator<< (std::ostream &ioOStream, const Triangle2D< T > &iTriangle)
template<typename T >
lass::io::MatlabOStreamoperator<< (lass::io::MatlabOStream &oOStream, const Triangle2D< T > &iTriangle)
template<typename T >
partialVoronoiArea (const Triangle2D< T > iT, int iIndexOfVertex)


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.


Member Typedef Documentation

template<typename T >
typedef Triangle2D<T> lass::prim::Triangle2D< T >::TSelf

Definition at line 68 of file triangle_2d.h.

template<typename T >
typedef Point2D<T> lass::prim::Triangle2D< T >::TPoint

Definition at line 70 of file triangle_2d.h.

template<typename T >
typedef Point2DH<T> lass::prim::Triangle2D< T >::TPointH

Definition at line 71 of file triangle_2d.h.

template<typename T >
typedef TPoint::TVector lass::prim::Triangle2D< T >::TVector

Definition at line 72 of file triangle_2d.h.

template<typename T >
typedef LineSegment2D<T> lass::prim::Triangle2D< T >::TLineSegment

Definition at line 73 of file triangle_2d.h.

template<typename T >
typedef TPoint::TValue lass::prim::Triangle2D< T >::TValue

Definition at line 75 of file triangle_2d.h.

template<typename T >
typedef TPoint::TParam lass::prim::Triangle2D< T >::TParam

Definition at line 76 of file triangle_2d.h.

template<typename T >
typedef TPoint::TReference lass::prim::Triangle2D< T >::TReference

Definition at line 77 of file triangle_2d.h.

template<typename T >
typedef TPoint::TConstReference lass::prim::Triangle2D< T >::TConstReference

Definition at line 78 of file triangle_2d.h.

template<typename T >
typedef TPoint::TNumTraits lass::prim::Triangle2D< T >::TNumTraits

Definition at line 79 of file triangle_2d.h.


Member Enumeration Documentation

template<typename T >
anonymous enum

Enumerator:
dimension 

Definition at line 81 of file triangle_2d.h.

template<typename T >
anonymous enum [private]

Enumerator:
size_ 

Definition at line 123 of file triangle_2d.h.


Constructor & Destructor Documentation

template<typename T >
lass::prim::Triangle2D< T >::Triangle2D (  )  [inline]

constructs an empty triangle.

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

Definition at line 61 of file triangle_2d.inl.

template<typename T >
lass::prim::Triangle2D< T >::Triangle2D ( const TPoint iA,
const TPoint iB,
const TPoint iC 
) [inline]

Constructs a triangle through three points in positive sequence.

Definition at line 70 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::vertices_.


Member Function Documentation

template<typename T >
const Triangle2D< T >::TPoint & lass::prim::Triangle2D< T >::operator[] ( int  iIndexOfVertex  )  const [inline]

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

Definition at line 82 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::isInRange(), LASS_ASSERT, and lass::prim::Triangle2D< T >::vertices_.

template<typename T >
Triangle2D< T >::TPoint & lass::prim::Triangle2D< T >::operator[] ( int  iIndexOfVertex  )  [inline]

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

Definition at line 93 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::isInRange(), LASS_ASSERT, and lass::prim::Triangle2D< T >::vertices_.

template<typename T >
const Triangle2D< T >::TPoint & lass::prim::Triangle2D< T >::at ( int  iIndexOfVertex  )  const [inline]

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:
an exception is thrown if polygon is empty

Definition at line 104 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::isInRange(), LASS_ASSERT, lass::num::mod(), lass::prim::Triangle2D< T >::size_, and lass::prim::Triangle2D< T >::vertices_.

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

template<typename T >
Triangle2D< T >::TPoint & lass::prim::Triangle2D< T >::at ( int  iIndexOfVertex  )  [inline]

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:
an exception is thrown if polygon is empty

Definition at line 116 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::isInRange(), LASS_ASSERT, lass::num::mod(), lass::prim::Triangle2D< T >::size_, and lass::prim::Triangle2D< T >::vertices_.

template<typename T >
const Triangle2D< T >::TLineSegment lass::prim::Triangle2D< T >::edge ( int  iIndexOfTailVertex  )  const [inline]

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

Exceptions:
an exception is thrown if polygon has less than two vertices

Definition at line 128 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::at().

template<typename T >
const Triangle2D< T >::TVector lass::prim::Triangle2D< T >::vector ( int  iIndexOfTailVertex  )  const [inline]

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

Definition at line 138 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::at().

template<typename T >
const bool lass::prim::Triangle2D< T >::isEmpty (  )  const [inline]

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.

References lass::prim::Triangle2D< T >::vertices_.

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

return number of vertices

Definition at line 160 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::size_.

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

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/
Warning:
polygon must be simple accoring degenerate policy.

Definition at line 170 of file triangle_2d.inl.

References LASS_ASSERT, lass::prim::perpDot(), lass::prim::Triangle2D< T >::size_, lass::stde::T, and lass::prim::Triangle2D< T >::vertices_.

Referenced by lass::prim::Triangle2D< T >::area(), and lass::prim::Triangle2D< T >::orientation().

template<typename T >
const Triangle2D< T >::TValue lass::prim::Triangle2D< T >::area (  )  const [inline]

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 lass::prim::Triangle2D< T >::signedArea().

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

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

return sum of the lengths of all edges

Definition at line 191 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::distance(), and lass::prim::Triangle2D< T >::vertices_.

template<typename T >
const Triangle2D< T >::TPointH lass::prim::Triangle2D< T >::vertexCentroid (  )  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 204 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::vertices_.

Referenced by lass::prim::Triangle2D< T >::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 lass::prim::Triangle2D< T >::vertexCentroid().

template<typename T >
const bool lass::prim::Triangle2D< T >::isSimple (  )  const [inline]

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.

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

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.

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

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

return orientation of polygon.

Warning:
polygon must be simple accoring DegeneratePolicy.

Definition at line 250 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::area(), lass::prim::oClockWise, lass::prim::oCounterClockWise, lass::prim::oInvalid, lass::prim::Triangle2D< T >::signedArea(), and lass::num::NumTraits< C >::zero.

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

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.

template<typename T >
const Side lass::prim::Triangle2D< T >::classify ( const TPoint iP  )  const [inline]

template<typename T >
const bool lass::prim::Triangle2D< T >::contains ( const TPoint iP  )  const [inline]

return true when a point is inside or on the edge of a triangle.

Definition at line 284 of file triangle_2d.inl.

References lass::prim::perpDot(), lass::prim::Triangle2D< T >::vertices_, and lass::num::NumTraits< C >::zero.

Referenced by lass::prim::Triangle2D< T >::classify().

template<typename T >
void lass::prim::Triangle2D< T >::flip (  )  [inline]

flip orientation of polygon.

Definition at line 305 of file triangle_2d.inl.

References std::swap(), and lass::prim::Triangle2D< T >::vertices_.

template<typename T >
const bool lass::prim::Triangle2D< T >::isInRange ( int  iIndexOfVertex  )  const [inline, private]

return if index of vertex is in range of the std::vector

Definition at line 317 of file triangle_2d.inl.

References lass::prim::Triangle2D< T >::size_.

Referenced by lass::prim::Triangle2D< T >::at(), and lass::prim::Triangle2D< T >::operator[]().


Friends And Related Function Documentation

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.

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.

References lass::prim::Ray2D< T, NormalizingPolicy, ParameterPolicy >::direction(), lass::prim::impl::intersectEdge2D(), LASS_ASSERT, lass::prim::rNone, lass::prim::rOne, and lass::prim::Ray2D< T, NormalizingPolicy, ParameterPolicy >::support().

template<typename T >
const T squaredDistance ( const Triangle2D< T > &  triangle,
const Point2D< T > &  point 
) [related]

Definition at line 329 of file triangle_2d.inl.

References lass::prim::dot(), and lass::prim::Vector2D< T >::squaredNorm().

template<typename T >
const T distance ( const Triangle2D< T > &  triangle,
const Point2D< T > &  point 
) [related]

Definition at line 361 of file triangle_2d.inl.

References sqrt(), and lass::prim::squaredDistance().

Referenced by lass::prim::Triangle2D< T >::perimeter().

template<typename T >
io::XmlOStream & operator<< ( io::XmlOStream ioOStream,
const Triangle2D< T > &  iTriangle 
) [related]

Definition at line 371 of file triangle_2d.inl.

References LASS_ENFORCE_STREAM.

template<typename T >
std::ostream & operator<< ( std::ostream &  ioOStream,
const Triangle2D< T > &  iTriangle 
) [related]

Definition at line 387 of file triangle_2d.inl.

References LASS_ENFORCE_STREAM.

template<typename T >
lass::io::MatlabOStream & operator<< ( lass::io::MatlabOStream oOStream,
const Triangle2D< T > &  iTriangle 
) [related]

Definition at line 397 of file triangle_2d.inl.

References lass::io::MatlabOStream::color(), and LASS_ENFORCE_STREAM.

template<typename T >
T partialVoronoiArea ( const Triangle2D< T >  iT,
int  iIndexOfVertex 
) [related]

Returns the surface of the partial Voronoi cell constructed around vertex iIndexOfVertex (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 415 of file triangle_2d.inl.

References lass::prim::Point2DH< T >::affine(), lass::prim::Triangle2D< T >::area(), lass::prim::Triangle2D< T >::at(), lass::prim::intersect(), LASS_ENFORCE, and lass::prim::rOne.


Field Documentation

template<typename T >
TPoint lass::prim::Triangle2D< T >::vertices_[size_] [private]


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

Generated on Mon Nov 10 14:22:14 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo