Library of Assembled Shared Sources
|
A very simple 2D polygon :) More...
#include <triangle_2d.h>
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> | |
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). | |
A very simple 2D polygon :)
Definition at line 64 of file triangle_2d.h.
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.
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.
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.
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);
an | exception 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().
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);
an | exception is thrown if polygon is empty |
Definition at line 116 of file triangle_2d.inl.
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).
an | exception is thrown if polygon has less than two vertices |
Definition at line 128 of file triangle_2d.inl.
References at().
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().
bool lass::prim::Triangle2D< T >::isEmpty | ( | ) | const |
return true if polygon has no vertices
Definition at line 150 of file triangle_2d.inl.
int lass::prim::Triangle2D< T >::size | ( | ) | const |
return number of vertices
Definition at line 160 of file triangle_2d.inl.
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
https://www.johndcook.com/blog/2018/09/26/polygon-area/
Definition at line 170 of file triangle_2d.inl.
Referenced by area(), and orientation().
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
Definition at line 181 of file triangle_2d.inl.
References lass::num::abs(), and signedArea().
Referenced by orientation(), and lass::prim::Triangle2D< U >::partialVoronoiArea().
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.
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.
Definition at line 204 of file triangle_2d.inl.
Referenced by surfaceCentroid().
|
inline |
return the barycenter of all vertices.
The vertex centroid is the homogenous sum of all vertices.
Definition at line 216 of file triangle_2d.inl.
References vertexCentroid().
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.
Definition at line 228 of file triangle_2d.inl.
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.
Definition at line 240 of file triangle_2d.inl.
Orientation lass::prim::Triangle2D< T >::orientation | ( | ) | const |
return orientation of polygon.
Definition at line 250 of file triangle_2d.inl.
References area(), lass::prim::oClockWise, lass::prim::oCounterClockWise, lass::prim::oInvalid, and signedArea().
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.
Definition at line 274 of file triangle_2d.inl.
|
determine axis aligned bounding box of a 2D triangle
Definition at line 60 of file aabb_2d_triangle_2d.h.
|
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.
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. |
Definition at line 72 of file ray_2d_triangle_2d.h.
|
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.