Library of Assembled Shared Sources
lass::prim::SimplePolygon3D< T, PlaneEquationPolicy, PlaneNormalizingPolicy > Class Template Reference

convex or concave polygon in 3D (not selfintersecting, no holes) More...

#include <simple_polygon_3d.h>

Inheritance diagram for lass::prim::SimplePolygon3D< T, PlaneEquationPolicy, PlaneNormalizingPolicy >:

Public Member Functions

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 TPlaneplane () const
 return support plane of polygon.
 
TPlaneplane ()
 access support plane of polygon.
 
const TVector normal () const
 return normal of plane
 
const XYZ majorAxis () const
 determines the major axis of the normal vector.
 
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 remove (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).
 
const SimplePolygon2D< T > mapping (XYZ iAxis) const
 maps a 3D polygon as a 2D polygon by ignoring the component along an axis.
 
bool contains (const TPoint &iP) const
 return true if a point iP is inside the polygon, on condition iP is on the plane
 
void flip ()
 flip normal and reverse sequence of vertices
 

Related Symbols

(Note that these are not member symbols.)

template<typename T, class EP1, class NP1, class NP2, class PP2>
Result intersect (const SimplePolygon3D< T, EP1, NP1 > &polygon, const Ray3D< T, NP2, PP2 > &triangle, T &t, const T &tMin)
 Find the intersection of a ray and a simple polygon by their parameter t on the ray.
 
template<typename T, class EP, class NP, class PP>
Result intersect (const SimplePolygon3D< T, EP, NP > &iPolygon, const LineSegment3D< T, PP > &iSegment, T &oT, const T &iMinT)
 Find the intersection of a line segment and a simple polygon by their parameter t on the line segment.
 

Detailed Description

template<typename T, class PlaneEquationPolicy = Cartesian, class PlaneNormalizingPolicy = Normalized>
class lass::prim::SimplePolygon3D< T, PlaneEquationPolicy, PlaneNormalizingPolicy >

convex or concave polygon in 3D (not selfintersecting, no holes)

Author
Bram de Greve [BdG]
Warning
SimplePolygon3D only assumes it's simple. there's no guarantee at any time. It's your own responsibility to keep it simple. We do it this way because it's just to costly to check it at every access to the polygon. However, we provide some methods to check it yourself.
also, SimplePolygon3D only assumes it's flat! It's up to you to feed it with vertices that are coplanar. However ... We provide tools to "flatten" it.

Definition at line 79 of file simple_polygon_3d.h.

Member Function Documentation

◆ at() [1/2]

template<typename T, class EP, class NP>
const SimplePolygon3D< T, EP, NP >::TPoint & lass::prim::SimplePolygon3D< T, EP, NP >::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 100 of file simple_polygon_3d.inl.

References at().

Referenced by at(), at(), and perimeter().

◆ at() [2/2]

template<typename T, class EP, class NP>
SimplePolygon3D< T, EP, NP >::TPoint & lass::prim::SimplePolygon3D< T, EP, NP >::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 114 of file simple_polygon_3d.inl.

References at().

◆ majorAxis()

template<typename T, class EP, class NP>
const XYZ lass::prim::SimplePolygon3D< T, EP, NP >::majorAxis ( ) const

determines the major axis of the normal vector.

The major axis is the one with the largest (absolute) component value. e.g. if the normal vector is (-1, 4, -8), this will be the z axis because abs(-8) > abs(4) > abs(-1). In case there's more than one major axis possible, the "highest" index is choosen. e.g. if the normal vector is (1, 1, 0), then y axis will be choosen, because y has a higher index than x .

Definition at line 186 of file simple_polygon_3d.inl.

References majorAxis().

Referenced by contains(), isSimple(), and majorAxis().

◆ signedArea()

template<typename T, class EP, class NP>
const SimplePolygon3D< T, EP, NP >::TValue lass::prim::SimplePolygon3D< T, EP, NP >::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/

Definition at line 260 of file simple_polygon_3d.inl.

References normal(), lass::prim::Vector3D< T >::normal(), signedArea(), and size().

Referenced by area(), orientation(), and signedArea().

◆ area()

template<typename T, class EP, class NP>
const SimplePolygon3D< T, EP, NP >::TValue lass::prim::SimplePolygon3D< T, EP, NP >::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 290 of file simple_polygon_3d.inl.

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

Referenced by area(), and orientation().

◆ vertexCentroid()

template<typename T, class EP, class NP>
const SimplePolygon3D< T, EP, NP >::TPointH lass::prim::SimplePolygon3D< T, EP, NP >::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 319 of file simple_polygon_3d.inl.

References size(), and vertexCentroid().

Referenced by surfaceCentroid(), and vertexCentroid().

◆ surfaceCentroid()

template<typename T, class EP, class NP>
const SimplePolygon3D< T, EP, NP >::TPointH lass::prim::SimplePolygon3D< T, EP, NP >::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

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 345 of file simple_polygon_3d.inl.

References normal(), lass::prim::Vector3D< T >::normal(), size(), surfaceCentroid(), and vertexCentroid().

Referenced by surfaceCentroid().

◆ isSimple()

template<typename T, class EP, class NP>
bool lass::prim::SimplePolygon3D< T, EP, NP >::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).

Definition at line 382 of file simple_polygon_3d.inl.

References isSimple(), majorAxis(), and mapping().

Referenced by isSimple().

◆ isConvex()

template<typename T, class EP, class NP>
bool lass::prim::SimplePolygon3D< T, EP, NP >::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).

Definition at line 406 of file simple_polygon_3d.inl.

References isConvex(), lass::num::sign(), sign(), size(), and vector().

Referenced by isConvex().

◆ orientation()

template<typename T, class EP, class NP>
Orientation lass::prim::SimplePolygon3D< T, EP, NP >::orientation ( ) const

return orientation of polygon

Warning
assumes polygon is simple

Definition at line 439 of file simple_polygon_3d.inl.

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

Referenced by orientation().

◆ isReflex()

template<typename T, class EP, class NP>
bool lass::prim::SimplePolygon3D< T, EP, NP >::isReflex ( int iIndexOfVertex) const

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

Warning
assumes polygon is simple

Definition at line 462 of file simple_polygon_3d.inl.

References isReflex(), normal(), and vector().

Referenced by isReflex().

◆ mapping()

template<typename T, class EP, class NP>
const SimplePolygon2D< T > lass::prim::SimplePolygon3D< T, EP, NP >::mapping ( XYZ iAxis) const

maps a 3D polygon as a 2D polygon by ignoring the component along an axis.

if iAxis is z, then it's easy. We ignore the z component and we get a polygon with only the x and y components.

if iAxis is x, then we have to keep the z axis while there's no z axis in 2D. We solve this by mapping the 3D y axis on the 2D x axis, and the 3D z axis on the 2D y axis.

if iAxis is y, then we have a similar problem. This time the 3D z axis is mapped on the 2D x axis, and the 3D x axis is mapped on the 2D y axis.

You can write this in short by saying the 2D x axis will correspond with 3D axis (iAxis

  • 1) and the 2D y axis with 3D axis (iAxis + 2).

Definition at line 487 of file simple_polygon_3d.inl.

References lass::prim::SimplePolygon2D< T, DegeneratePolicy >::add(), mapping(), and size().

Referenced by isSimple(), and mapping().

◆ contains()

template<typename T, class EP, class NP>
bool lass::prim::SimplePolygon3D< T, EP, NP >::contains ( const TPoint & iP) const

return true if a point iP is inside the polygon, on condition iP is on the plane

Algorithm:
comp.graphics.algorithms Frequently Asked Questions: Subject 2.03: "How do I find if a point lies within a polygon?" http://www.faqs.org/faqs/graphics/algorithms-faq/

Definition at line 520 of file simple_polygon_3d.inl.

References contains(), majorAxis(), and size().

Referenced by contains(), lass::prim::SimplePolygon3D< U, PlaneEquationPolicy, PlaneNormalizingPolicy >::intersect(), and lass::prim::SimplePolygon3D< U, PlaneEquationPolicy, PlaneNormalizingPolicy >::intersect().

Friends And Related Symbol Documentation

◆ intersect() [1/2]

template<typename T, class EP1, class NP1, class NP2, class PP2>
Result intersect ( const SimplePolygon3D< T, EP1, NP1 > & polygon,
const Ray3D< T, NP2, PP2 > & triangle,
T & t,
const T & tMin )
related

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

Parameters
polygon[in] the simple polygon
triangle[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 69 of file ray_3d_simple_polygon_3d.h.

◆ intersect() [2/2]

template<typename T, class EP, class NP, class PP>
Result intersect ( const SimplePolygon3D< T, EP, NP > & iPolygon,
const LineSegment3D< T, PP > & iSegment,
T & oT,
const T & iMinT )
related

Find the intersection of a line segment and a simple polygon by their parameter t on the line segment.

Parameters
iPolygon[in] the simple polygon
iSegment[in] the line segment
oT[out] the parameter of the intersection point > iMinT.
iMinT[in] the minimum t that may be returned as valid intersection.
Returns
  • rNone no intersections with oT > iMinT found oT is not assigned.
  • rOne a intersection with oT > iMinT is found oT is assigned.

Definition at line 583 of file simple_polygon_3d.inl.


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