Library of Assembled Shared Sources
|
convex or concave polygon in 2D (not selfintersecting, no holes) More...
#include <simple_polygon_2d.h>
Public Member Functions | |
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)\ | |
void | add (const TPoint &iVertex) |
add a point at the "end" of the vertex list. | |
void | insert (int iIndexOfVertex, const TPoint &iVertex) |
insert a vertex at iIndex (so it will sit before the current at(iIndex)). | |
void | erase (int iIndexOfVertex) |
remove the vertex at(iIndex) | |
bool | isEmpty () const |
return true if polygon has no vertices | |
size_t | 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 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. | |
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 a polygon. | |
void | flip () |
flip orientation of polygon. | |
void | fixDegenerate () |
fixes degenerate polygons as far as possible. | |
bool | isValid () const |
a simple polygon is valid if it is not degenerate. | |
Related Symbols | |
(Note that these are not member symbols.) | |
template<typename T, class DP, class NP, class PP> | |
Result | intersect (const SimplePolygon2D< T, DP > &polygon, 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, typename DP, typename PP> | |
bool | intersects (const SimplePolygon2D< T, DP > &poly, const LineSegment2D< T, PP > &segment) |
O(N) with N is size of poly. | |
template<typename T, typename DP, typename PP> | |
bool | intersects (const LineSegment2D< T, PP > &segment, const SimplePolygon2D< T, DP > &poly) |
O(N) with N is size of poly. | |
template<typename T, typename DP1, typename DP2> | |
bool | intersects (const SimplePolygon2D< T, DP1 > &a, const SimplePolygon2D< T, DP2 > &b) |
O(M+N) with M and N the sizes of the polygons. | |
convex or concave polygon in 2D (not selfintersecting, no holes)
Definition at line 73 of file simple_polygon_2d.h.
const SimplePolygon2D< T, DP >::TPoint & lass::prim::SimplePolygon2D< T, DP >::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);
an | exception is thrown if polygon is empty |
Definition at line 113 of file simple_polygon_2d.inl.
References at().
Referenced by at(), at(), edge(), fixDegenerate(), and vector().
SimplePolygon2D< T, DP >::TPoint & lass::prim::SimplePolygon2D< T, DP >::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);
an | exception is thrown if polygon is empty |
Definition at line 129 of file simple_polygon_2d.inl.
References at().
const SimplePolygon2D< T, DP >::TLineSegment lass::prim::SimplePolygon2D< T, DP >::edge | ( | int | iIndexOfTailVertex | ) | 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 145 of file simple_polygon_2d.inl.
Referenced by edge(), lass::prim::SimplePolygon2D< T, NoDegenerate >::intersects(), lass::prim::SimplePolygon2D< T, NoDegenerate >::intersects(), and isSimple().
void lass::prim::SimplePolygon2D< T, DP >::add | ( | const TPoint & | iVertex | ) |
add a point at the "end" of the vertex list.
this is almost the same as insert(0, iVertex)
with the difference that add(iVertex)
is also valid for empty polygons.
Definition at line 170 of file simple_polygon_2d.inl.
References add().
Referenced by add(), and lass::prim::SimplePolygon3D< T, PlaneEquationPolicy, PlaneNormalizingPolicy >::mapping().
const SimplePolygon2D< T, DP >::TValue lass::prim::SimplePolygon2D< T, DP >::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 241 of file simple_polygon_2d.inl.
References signedArea(), and size().
Referenced by area(), fixDegenerate(), isReflex(), isValid(), and signedArea().
const SimplePolygon2D< T, DP >::TValue lass::prim::SimplePolygon2D< T, DP >::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 274 of file simple_polygon_2d.inl.
References lass::num::abs(), area(), and signedArea().
Referenced by area().
const SimplePolygon2D< T, DP >::TPointH lass::prim::SimplePolygon2D< T, DP >::vertexCentroid | ( | ) | const |
return the barycenter of all vertices.
The vertex centroid is the homogenous sum of all vertices.
Definition at line 319 of file simple_polygon_2d.inl.
References size(), and vertexCentroid().
Referenced by surfaceCentroid(), and vertexCentroid().
const SimplePolygon2D< T, DP >::TPointH lass::prim::SimplePolygon2D< T, DP >::surfaceCentroid | ( | ) | const |
return the centroid of the filled polygon.
Eric W. Weisstein. "Geometric Centroid." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/GeometricCentroid.html
Definition at line 346 of file simple_polygon_2d.inl.
References size(), surfaceCentroid(), and vertexCentroid().
Referenced by surfaceCentroid().
bool lass::prim::SimplePolygon2D< T, DP >::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 380 of file simple_polygon_2d.inl.
References edge(), intersect(), isSimple(), lass::prim::rNone, lass::prim::rOne, and size().
Referenced by fixDegenerate(), isSimple(), and isValid().
bool lass::prim::SimplePolygon2D< T, DP >::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 432 of file simple_polygon_2d.inl.
References isConvex(), lass::num::sign(), sign(), size(), and vector().
Referenced by isConvex().
Orientation lass::prim::SimplePolygon2D< T, DP >::orientation | ( | ) | const |
return orientation of polygon.
Definition at line 286 of file simple_polygon_2d.inl.
References lass::prim::oClockWise, lass::prim::oCounterClockWise, lass::prim::oInvalid, and orientation().
Referenced by orientation().
bool lass::prim::SimplePolygon2D< T, DP >::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 477 of file simple_polygon_2d.inl.
References isEmpty(), isReflex(), signedArea(), and vector().
Referenced by isReflex().
bool lass::prim::SimplePolygon2D< T, DP >::contains | ( | const TPoint & | iP | ) | const |
return true when a point is inside or on a polygon.
When a point lies on a polygon edge the answer can either be true or false but in a way that for a meshing the answer will only be true for one polygon. More precise: for polygons sharing an edge only one of them will return true for a point on the edge. For an explanation of how this exactly works: http://www.ecse.rpi.edu/Homepages/wrf/geom/pnpoly.html (Wm Randolph Franklin)
Definition at line 502 of file simple_polygon_2d.inl.
References contains(), and size().
Referenced by contains(), and lass::prim::SimplePolygon2D< T, NoDegenerate >::intersects().
void lass::prim::SimplePolygon2D< T, DP >::fixDegenerate | ( | ) |
fixes degenerate polygons as far as possible.
things that can be repared are:
Things that can't repared (and will cause an exception to be thrown) are:
Definition at line 555 of file simple_polygon_2d.inl.
References at(), erase(), fixDegenerate(), isSimple(), signedArea(), size(), and vector().
Referenced by fixDegenerate().
|
Find the intersection of a ray and a triangle by their parameter t on the ray.
polygon | [in] the simple polygon |
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 71 of file ray_2d_simple_polygon_2d.h.
Referenced by isSimple().