Visual Computing Library
|
The Polygon class represents a polygon in a N-dimensional Euclidean space. More...
#include <vclib/space/core/polygon.h>
Public Types | |
using | ScalarType = PointT::ScalarType |
The scalar type of the points that define the polygon. | |
using | PointType = PointT |
The type of the points that define the polygon. | |
using | Iterator = typename std::vector< PointT >::iterator |
The iterator type of the polygon. | |
using | ConstIterator = typename std::vector< PointT >::const_iterator |
The const iterator type of the polygon. | |
Public Member Functions | |
Polygon () | |
Construct a new empty Polygon object. | |
Polygon (std::initializer_list< PointT > points) | |
Construct a new Polygon object from an initializer list of points. | |
template<typename Iterator > requires (std::is_same_v<typename Iterator::value_type, PointT>) | |
Polygon (Iterator begin, Iterator end) | |
Construct a new Polygon object from a range of points. | |
template<Range R> requires (InputRange<R, PointT>) | |
Polygon (R &&range) | |
Construct a new Polygon object from a range of points. | |
uint | size () const |
Returns the number of points that define the polygon. | |
void | resize (uint n) |
Resizes the polygon to contain n points. | |
void | reserve (uint n) |
Reserves space for n points in the polygon. | |
void | clear () |
Clears the polygon, removing all points. | |
void | pushBack (const PointT &point) |
Adds a point to the back of the polygon. | |
void | pushBack (PointT &&point) |
Adds a point to the back of the polygon. | |
PointT & | point (uint i) |
Returns the point at index i in the polygon. | |
const PointT & | point (uint i) const |
Returns the point at index i in the polygon. | |
ScalarType | sideLength (uint i) const |
Returns the side length of the i-th side of the polygon. | |
PointT | normal () const |
Computes the normal of the polygon. | |
PointT | barycenter () const |
Computes the barycenter of the polygon. | |
template<typename WIterator > | |
PointT | weightedBarycenter (WIterator wBegin) const |
Computes the weighted barycenter of the polygon. | |
ScalarType | perimeter () const |
Returns the perimeter of the polygon. | |
ScalarType | area () const |
Returns the area of the polygon. | |
PointType & | operator[] (uint i) |
Returns the i-th point of the polygon. | |
const PointType & | operator[] (uint i) const |
Returns the i-th point of the polygon. | |
Iterator | begin () |
Returns an iterator pointing to the first point of the polygon. | |
Iterator | end () |
Returns an iterator pointing past the last point of the polygon. | |
ConstIterator | begin () const |
Returns a const iterator pointing to the first point of the polygon. | |
ConstIterator | end () const |
Returns a const iterator pointing past the last point of the polygon. | |
Static Public Member Functions | |
template<typename Iterator > requires ( std::is_same_v<typename Iterator::value_type, PointT> && PointT::DIM == 3) | |
static PointT | normal (Iterator begin, Iterator end) |
Computes the normal of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon. | |
template<Range R> | |
static PointT | normal (R &&range) |
Computes the normal of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon. | |
template<typename Iterator > requires (std::is_same_v<typename Iterator::value_type, PointT>) | |
static PointT | barycenter (Iterator begin, Iterator end) |
Computes the barycenter of a container of points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon. | |
template<Range R> | |
static PointT | barycenter (R &&range) |
Computes the barycenter of a container of points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon. | |
template<typename Iterator , typename WIterator > requires (std::is_same_v<typename Iterator::value_type, PointT>) | |
static PointT | weightedBarycenter (Iterator begin, Iterator end, WIterator wBegin) |
Computes the weighted barycenter of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon. Weights are iterated by another iterator wBegin, which iterates to a container of the same size of the polygon container. | |
template<Range Rp, Range Rw> | |
static PointT | weightedBarycenter (Rp &&rPolygon, Rw &&rWeights) |
Computes the weighted barycenter of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon. Weights are iterated by another iterator wBegin, which iterates to a container of the same size of the polygon container. | |
template<typename Iterator > requires (std::is_same_v<typename Iterator::value_type, PointT>) | |
static ScalarType | perimeter (Iterator begin, Iterator end) |
Calculates the perimeter of a polygon defined by a range of points. | |
template<Range R> | |
static ScalarType | perimeter (R &&range) |
Calculates the perimeter of a polygon defined by a range of points. | |
template<typename Iterator > requires (std::is_same_v<typename Iterator::value_type, PointT>) | |
static ScalarType | area (Iterator begin, Iterator end) |
Calculates the area of a polygon. This function works also with simple triangles, but it is less efficient thant the function "Triangle<PointT>::area()". | |
template<Range R> | |
static ScalarType | area (R &&range) |
Calculates the area of a polygon. This function works also with simple triangles, but it is less efficient thant the function "Triangle<PointT>::area()". | |
Static Public Attributes | |
static const uint | DIM = PointT::DIM |
The dimension of the points that define the polygon. | |
Private Attributes | |
std::vector< PointT > | mPoints |
The Polygon class represents a polygon in a N-dimensional Euclidean space.
The class allows to store a sequence of points that define a polygon, and provides a set of member functions to compute properties of the polygon, such as the normal, the barycenter, the perimeter, the area... The class also provides a series of static member functions to compute these properties for a polygon defined by a range of points.
PointT | The type of the points that define the polygon. |
|
inline |
Construct a new Polygon object from an initializer list of points.
[in] | points | the list of points that define the polygon. |
|
inline |
Construct a new Polygon object from a range of points.
Iterator | an iterator which points to a type that satisfies the PointConcept. |
[in] | begin | iterator pointing to the first point of the polygon. |
[in] | end | end iterator. |
|
inline |
Construct a new Polygon object from a range of points.
R | a range of points that satisfy the PointConcept. |
[in] | range | the range of points that define the polygon. |
|
inline |
Returns the area of the polygon.
|
inlinestatic |
Calculates the area of a polygon. This function works also with simple triangles, but it is less efficient thant the function "Triangle<PointT>::area()".
Iterator | an iterator which points to a type that satisfies the PointConcept. |
[in] | begin | an iterator pointing to the first point in the polygon |
[in] | end | an iterator pointing past the last point in the polygon |
|
inlinestatic |
Calculates the area of a polygon. This function works also with simple triangles, but it is less efficient thant the function "Triangle<PointT>::area()".
R | a range of points that satisfy the PointConcept. |
[in] | range | the range of points that define the polygon. |
|
inline |
Computes the barycenter of the polygon.
The barycenter is computed as the average of the points that define the polygon.
|
inlinestatic |
Computes the barycenter of a container of points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon.
Iterator | an iterator which points to a type that satisfies the PointConcept. |
[in] | begin | iterator pointing to the first point of the polygon. |
[in] | end | end iterator |
|
inlinestatic |
Computes the barycenter of a container of points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon.
R | a range of points that satisfy the PointConcept. |
[in] | range | the range of points that define the polygon. |
|
inline |
Computes the normal of the polygon.
The normal is computed as the normalized sum of the cross products of each triplet of consecutive points.
|
inlinestatic |
Computes the normal of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon.
The normal is computed as the normalized sum of the cross products of each triplet of consecutive points.
Iterator | an iterator which points to a type that satisfies the PointConcept. |
[in] | begin | iterator pointing to the first point of the polygon. |
[in] | end | end iterator |
|
inlinestatic |
Computes the normal of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon.
R | a range of points that satisfy the PointConcept. |
[in] | range | the range of points that define the polygon. |
|
inline |
Returns the i-th point of the polygon.
i | the index of the point to return. |
|
inline |
Returns the i-th point of the polygon.
i | the index of the point to return. |
|
inline |
Returns the perimeter of the polygon.
|
inlinestatic |
Calculates the perimeter of a polygon defined by a range of points.
The function calculates the perimeter of a polygon defined by a range of points. The function takes two iterators as input, representing the beginning and end of the range of points. The points in the range must satisfy the PointConcept, which is a concept that requires the point type to have a ScalarType and a dist() function that calculates the distance between two points.
Iterator | an iterator which points to a type that satisfies the PointConcept. |
[in] | begin | An iterator pointing to the first point in the range. |
[in] | end | An iterator pointing to one past the last point in the range. |
|
inlinestatic |
Calculates the perimeter of a polygon defined by a range of points.
R | a range of points that satisfy the PointConcept. |
[in] | range | the range of points that define the polygon. |
|
inline |
Returns the point at index i in the polygon.
[in] | i | the index of the point to return. |
|
inline |
Returns the point at index i in the polygon.
[in] | i | the index of the point to return. |
|
inline |
Adds a point to the back of the polygon.
[in] | point | the point to add to the polygon. |
|
inline |
Adds a point to the back of the polygon.
[in] | point | the point to add to the polygon. |
|
inline |
Reserves space for n points in the polygon.
[in] | n | the number of points for which to reserve space. |
|
inline |
Resizes the polygon to contain n points.
[in] | n | the number of points that the polygon should contain. |
|
inline |
Returns the side length of the i-th side of the polygon.
The i-th side is the side that connects the i-th point with the (i+1)-th point, where the indices are taken modulo the number of points in the polygon.
[in] | i | the index of the side for which to compute the length. |
|
inline |
Returns the number of points that define the polygon.
|
inlinestatic |
Computes the weighted barycenter of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon. Weights are iterated by another iterator wBegin, which iterates to a container of the same size of the polygon container.
Iterator | an iterator which points to a type that satisfies the PointConcept. |
WIterator | an iterator which points to a scalar type. |
[in] | begin | iterator pointing to the first point of the polygon. |
[in] | end | end iterator of the polygon container. |
[in] | wBegin | iterator pointing to the first weight associated to the fist polygon point. |
|
inlinestatic |
Computes the weighted barycenter of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon. Weights are iterated by another iterator wBegin, which iterates to a container of the same size of the polygon container.
Rp | a range of points that satisfy the PointConcept. |
Rw | a range of weights. |
[in] | rPolygon | the range of points that define the polygon. |
[in] | rWeights | the range of weights associated to the points. |
|
inline |
Computes the weighted barycenter of the polygon.
The weighted barycenter is computed as the weighted average of the points that define the polygon. The weights are provided by a container of the same size as the polygon, iterated by the iterator wBegin.
WIterator | an iterator which points to a scalar type. |
[in] | wBegin | iterator pointing to the first weight associated to the fist polygon point. |