Visual Computing Library
All Classes Functions Variables Typedefs Enumerations Friends Modules Pages Concepts
vcl::Polygon< PointT > Class Template Reference

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.
 
PointTypeoperator[] (uint i)
 Returns the i-th point of the polygon.
 
const PointTypeoperator[] (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
 

Detailed Description

template<PointConcept PointT>
class vcl::Polygon< PointT >

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.

Template Parameters
PointTThe type of the points that define the polygon.

Constructor & Destructor Documentation

◆ Polygon() [1/3]

template<PointConcept PointT>
vcl::Polygon< PointT >::Polygon ( std::initializer_list< PointT >  points)
inline

Construct a new Polygon object from an initializer list of points.

Parameters
[in]pointsthe list of points that define the polygon.

◆ Polygon() [2/3]

template<PointConcept PointT>
template<typename Iterator >
requires (std::is_same_v<typename Iterator::value_type, PointT>)
vcl::Polygon< PointT >::Polygon ( Iterator  begin,
Iterator  end 
)
inline

Construct a new Polygon object from a range of points.

Template Parameters
Iteratoran iterator which points to a type that satisfies the PointConcept.
Parameters
[in]beginiterator pointing to the first point of the polygon.
[in]endend iterator.

◆ Polygon() [3/3]

template<PointConcept PointT>
template<Range R>
requires (InputRange<R, PointT>)
vcl::Polygon< PointT >::Polygon ( R &&  range)
inline

Construct a new Polygon object from a range of points.

Template Parameters
Ra range of points that satisfy the PointConcept.
Parameters
[in]rangethe range of points that define the polygon.

Member Function Documentation

◆ area() [1/3]

template<PointConcept PointT>
ScalarType vcl::Polygon< PointT >::area ( ) const
inline

Returns the area of the polygon.

Returns
The area of the polygon.

◆ area() [2/3]

template<PointConcept PointT>
template<typename Iterator >
requires (std::is_same_v<typename Iterator::value_type, PointT>)
static ScalarType vcl::Polygon< PointT >::area ( Iterator  begin,
Iterator  end 
)
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()".

Template Parameters
Iteratoran iterator which points to a type that satisfies the PointConcept.
Parameters
[in]beginan iterator pointing to the first point in the polygon
[in]endan iterator pointing past the last point in the polygon
Returns
the area of the polygon
Note
The points in the polygon must have a scalar type, and must satisfy the PointConcept concept.
The polygon must be simple, i.e., it cannot intersect itself.

◆ area() [3/3]

template<PointConcept PointT>
template<Range R>
static ScalarType vcl::Polygon< PointT >::area ( R &&  range)
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()".

Template Parameters
Ra range of points that satisfy the PointConcept.
Parameters
[in]rangethe range of points that define the polygon.
Returns
The area of the polygon.

◆ barycenter() [1/3]

template<PointConcept PointT>
PointT vcl::Polygon< PointT >::barycenter ( ) const
inline

Computes the barycenter of the polygon.

The barycenter is computed as the average of the points that define the polygon.

Returns
The barycenter of the polygon.

◆ barycenter() [2/3]

template<PointConcept PointT>
template<typename Iterator >
requires (std::is_same_v<typename Iterator::value_type, PointT>)
static PointT vcl::Polygon< PointT >::barycenter ( Iterator  begin,
Iterator  end 
)
inlinestatic

Computes the barycenter of a container of points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon.

Template Parameters
Iteratoran iterator which points to a type that satisfies the PointConcept.
Parameters
[in]beginiterator pointing to the first point of the polygon.
[in]endend iterator
Returns
The barycenter of the polygon.

◆ barycenter() [3/3]

template<PointConcept PointT>
template<Range R>
static PointT vcl::Polygon< PointT >::barycenter ( R &&  range)
inlinestatic

Computes the barycenter of a container of points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon.

Template Parameters
Ra range of points that satisfy the PointConcept.
Parameters
[in]rangethe range of points that define the polygon.
Returns
The barycenter of the polygon.

◆ normal() [1/3]

template<PointConcept PointT>
PointT vcl::Polygon< PointT >::normal ( ) const
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.

Note
This function requires that the dimension of the points that define the polygon is 3.
Returns
The normal of the polygon.

◆ normal() [2/3]

template<PointConcept PointT>
template<typename Iterator >
requires ( std::is_same_v<typename Iterator::value_type, PointT> && PointT::DIM == 3)
static PointT vcl::Polygon< PointT >::normal ( Iterator  begin,
Iterator  end 
)
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.

Template Parameters
Iteratoran iterator which points to a type that satisfies the PointConcept.
Parameters
[in]beginiterator pointing to the first point of the polygon.
[in]endend iterator
Returns
The normal of the polygon.

◆ normal() [3/3]

template<PointConcept PointT>
template<Range R>
static PointT vcl::Polygon< PointT >::normal ( R &&  range)
inlinestatic

Computes the normal of a container of 3D points iterated between the iterators begin and end, listed in counterclockwise order, representing a polygon.

Template Parameters
Ra range of points that satisfy the PointConcept.
Parameters
[in]rangethe range of points that define the polygon.
Returns
The normal of the polygon.

◆ operator[]() [1/2]

template<PointConcept PointT>
PointType & vcl::Polygon< PointT >::operator[] ( uint  i)
inline

Returns the i-th point of the polygon.

Parameters
ithe index of the point to return.
Returns
The i-th point of the polygon.

◆ operator[]() [2/2]

template<PointConcept PointT>
const PointType & vcl::Polygon< PointT >::operator[] ( uint  i) const
inline

Returns the i-th point of the polygon.

Parameters
ithe index of the point to return.
Returns
The i-th point of the polygon.

◆ perimeter() [1/3]

template<PointConcept PointT>
ScalarType vcl::Polygon< PointT >::perimeter ( ) const
inline

Returns the perimeter of the polygon.

Returns
The perimeter of the polygon.

◆ perimeter() [2/3]

template<PointConcept PointT>
template<typename Iterator >
requires (std::is_same_v<typename Iterator::value_type, PointT>)
static ScalarType vcl::Polygon< PointT >::perimeter ( Iterator  begin,
Iterator  end 
)
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.

Template Parameters
Iteratoran iterator which points to a type that satisfies the PointConcept.
Parameters
[in]beginAn iterator pointing to the first point in the range.
[in]endAn iterator pointing to one past the last point in the range.
Returns
The perimeter of the polygon defined by the range of points.

◆ perimeter() [3/3]

template<PointConcept PointT>
template<Range R>
static ScalarType vcl::Polygon< PointT >::perimeter ( R &&  range)
inlinestatic

Calculates the perimeter of a polygon defined by a range of points.

Template Parameters
Ra range of points that satisfy the PointConcept.
Parameters
[in]rangethe range of points that define the polygon.
Returns
The perimeter of the polygon.

◆ point() [1/2]

template<PointConcept PointT>
PointT & vcl::Polygon< PointT >::point ( uint  i)
inline

Returns the point at index i in the polygon.

Parameters
[in]ithe index of the point to return.

◆ point() [2/2]

template<PointConcept PointT>
const PointT & vcl::Polygon< PointT >::point ( uint  i) const
inline

Returns the point at index i in the polygon.

Parameters
[in]ithe index of the point to return.

◆ pushBack() [1/2]

template<PointConcept PointT>
void vcl::Polygon< PointT >::pushBack ( const PointT &  point)
inline

Adds a point to the back of the polygon.

Parameters
[in]pointthe point to add to the polygon.

◆ pushBack() [2/2]

template<PointConcept PointT>
void vcl::Polygon< PointT >::pushBack ( PointT &&  point)
inline

Adds a point to the back of the polygon.

Parameters
[in]pointthe point to add to the polygon.

◆ reserve()

template<PointConcept PointT>
void vcl::Polygon< PointT >::reserve ( uint  n)
inline

Reserves space for n points in the polygon.

Parameters
[in]nthe number of points for which to reserve space.

◆ resize()

template<PointConcept PointT>
void vcl::Polygon< PointT >::resize ( uint  n)
inline

Resizes the polygon to contain n points.

Parameters
[in]nthe number of points that the polygon should contain.

◆ sideLength()

template<PointConcept PointT>
ScalarType vcl::Polygon< PointT >::sideLength ( uint  i) const
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.

Parameters
[in]ithe index of the side for which to compute the length.

◆ size()

template<PointConcept PointT>
uint vcl::Polygon< PointT >::size ( ) const
inline

Returns the number of points that define the polygon.

Returns
The number of points that define the polygon.

◆ weightedBarycenter() [1/3]

template<PointConcept PointT>
template<typename Iterator , typename WIterator >
requires (std::is_same_v<typename Iterator::value_type, PointT>)
static PointT vcl::Polygon< PointT >::weightedBarycenter ( Iterator  begin,
Iterator  end,
WIterator  wBegin 
)
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.

Template Parameters
Iteratoran iterator which points to a type that satisfies the PointConcept.
WIteratoran iterator which points to a scalar type.
Parameters
[in]beginiterator pointing to the first point of the polygon.
[in]endend iterator of the polygon container.
[in]wBeginiterator pointing to the first weight associated to the fist polygon point.
Returns
The weighted barycenter of the polygon.

◆ weightedBarycenter() [2/3]

template<PointConcept PointT>
template<Range Rp, Range Rw>
static PointT vcl::Polygon< PointT >::weightedBarycenter ( Rp &&  rPolygon,
Rw &&  rWeights 
)
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.

Template Parameters
Rpa range of points that satisfy the PointConcept.
Rwa range of weights.
Parameters
[in]rPolygonthe range of points that define the polygon.
[in]rWeightsthe range of weights associated to the points.
Returns
The weighted barycenter of the polygon.

◆ weightedBarycenter() [3/3]

template<PointConcept PointT>
template<typename WIterator >
PointT vcl::Polygon< PointT >::weightedBarycenter ( WIterator  wBegin) const
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.

Template Parameters
WIteratoran iterator which points to a scalar type.
Parameters
[in]wBeginiterator pointing to the first weight associated to the fist polygon point.
Returns
The weighted barycenter of the polygon.

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