Core 1.0
Public Member Functions | Protected Attributes | Friends | List of all members
Polygonal Class Reference

Polygons. More...

#include <polygon.h>

Public Member Functions

 Polygonal ()
 Create an empty polygon.
 
 Polygonal (Vector *, int)
 Create a polygon given an array of points. More...
 
 Polygonal (const QVector< Vector > &)
 Create a polygon. More...
 
 Polygonal (const QVector< Vector2 > &)
 Create a planar polygon. More...
 
 Polygonal (const QVector< Segment > &)
 Create a polygon from a set of segments. More...
 
 Polygonal (const Box2 &)
 Create a polygon from a box. More...
 
Box GetBox () const
 Compute the bounding box. More...
 
void Translate (const Vector &)
 Translate the polygon by a given vector. More...
 
void Scale (const double &)
 Scale the polygon by a given factor. More...
 
void Rotate (const Matrix &)
 Rotate the polygon. More...
 
void Append (const Vector &)
 Add a vertex to the polygon. More...
 
VectorVertex (int)
 Read write access to the i-th point.
 
Vector Vertex (int) const
 Read only access to the i-th point.
 
int Size () const
 Return the number of vertices of the polygon.
 
double Length () const
 Compute the perimeter of the polygon.
 
double PlanarLength () const
 Compute the perimeter of the projection of the polygon on the horizontal plane. More...
 
Vector PointAtLength (const double &) const
 Return the position of the point on the polygon at a given length from the starting point. More...
 
Vector NormalAtLength (const double &) const
 Return the normal at the position of the point on the polygon. More...
 
double Area () const
 Compute the area of the polygon.
 
Vector Centroid () const
 Compute the centroid of the polygon. More...
 
Vector Center () const
 Compute the barycenter of the polygon. More...
 
void Subdivide (int, QVector< Vector > &, QVector< int > &) const
 Create an n-adic subdivision of a polygon. More...
 

Protected Attributes

QVector< Vectorq
 Array of vertices.
 

Friends

std::ostream & operator<< (std::ostream &, const Polygonal &)
 Overloaded stream operator. More...
 

Detailed Description

Polygons.

The name of this class was chosen to avoid conflicts with a pre-defined windows open-GL class.

Note that polygons can be non-convex.

Constructor & Destructor Documentation

◆ Polygonal() [1/5]

Polygonal::Polygonal ( Vector a,
int  n 
)
explicit

Create a polygon given an array of points.

Note that the points should be provided in trigonometric order.

Parameters
aArray of vertices.
nSize.

◆ Polygonal() [2/5]

Polygonal::Polygonal ( const QVector< Vector > &  p)
explicit

Create a polygon.

Parameters
pArray of points.

◆ Polygonal() [3/5]

Polygonal::Polygonal ( const QVector< Vector2 > &  p)
explicit

Create a planar polygon.

Parameters
pArray of points.

◆ Polygonal() [4/5]

Polygonal::Polygonal ( const QVector< Segment > &  e)
explicit

Create a polygon from a set of segments.

The polygon is created from the first vertices of all segments.

Parameters
eArray of segments.

◆ Polygonal() [5/5]

Polygonal::Polygonal ( const Box2 box)
explicit

Create a polygon from a box.

Parameters
boxThe box.

Member Function Documentation

◆ Append()

void Polygonal::Append ( const Vector p)
inline

Add a vertex to the polygon.

Parameters
pPoint.

◆ Center()

Vector Polygonal::Center ( ) const

Compute the barycenter of the polygon.

Note that the barycenter is not the same as the centroid.

See also
Centroid

◆ Centroid()

Vector Polygonal::Centroid ( ) const

Compute the centroid of the polygon.

Note that the centroid is not the same as the barycenter.

See also
Barycenter

◆ GetBox()

Box Polygonal::GetBox ( ) const

Compute the bounding box.

The polygon should have some vertices, otherwise the result is undefined.

◆ NormalAtLength()

Vector Polygonal::NormalAtLength ( const double &  length) const

Return the normal at the position of the point on the polygon.

Parameters
lengthGiven length from the starting point.

◆ PlanarLength()

double Polygonal::PlanarLength ( ) const

Compute the perimeter of the projection of the polygon on the horizontal plane.

This is equivalent to projecting the polygon on the plane and computing its perimeter:

double length = Polygon2(p).Length();
Polygons in the plane.
Definition: polygon.h:91
double Length() const
Compute the perimeter of the polygon.
Definition: polygon2.cpp:166
Polygons.
Definition: polygon.h:13

◆ PointAtLength()

Vector Polygonal::PointAtLength ( const double &  length) const

Return the position of the point on the polygon at a given length from the starting point.

Parameters
lengthDistance on the perimeter of the polygon. Note that it should be less than the perimeter of the polygon, still a modulo operation is performed inside.

◆ Rotate()

void Polygonal::Rotate ( const Matrix r)

Rotate the polygon.

Parameters
rRotation matrix.

◆ Scale()

void Polygonal::Scale ( const double &  s)

Scale the polygon by a given factor.

Parameters
sScaling factor.

◆ Subdivide()

void Polygonal::Subdivide ( int  n,
QVector< Vector > &  vertex,
QVector< int > &  index 
) const

Create an n-adic subdivision of a polygon.

Note that the polygon should be star-shaped.

This function first computes the barycenter of the polygon and uses it to create triangles which are subdivided.

Parameters
nSubdivision level.
vertexArray of points.
indexArray of indexes defining the triangles.

◆ Translate()

void Polygonal::Translate ( const Vector t)

Translate the polygon by a given vector.

Parameters
tVector.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Polygonal p 
)
friend

Overloaded stream operator.

Parameters
sStream.
pPolygon.