Core 1.0
|
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... | |
Vector & | Vertex (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< Vector > | q |
Array of vertices. | |
Friends | |
std::ostream & | operator<< (std::ostream &, const Polygonal &) |
Overloaded stream operator. More... | |
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.
|
explicit |
Create a polygon given an array of points.
Note that the points should be provided in trigonometric order.
a | Array of vertices. |
n | Size. |
|
explicit |
Create a polygon.
p | Array of points. |
|
explicit |
Create a planar polygon.
p | Array of points. |
|
explicit |
Create a polygon from a set of segments.
The polygon is created from the first vertices of all segments.
e | Array of segments. |
|
explicit |
Create a polygon from a box.
box | The box. |
|
inline |
Add a vertex to the polygon.
p | Point. |
Vector Polygonal::Center | ( | ) | const |
Compute the barycenter of the polygon.
Note that the barycenter is not the same as the centroid.
Vector Polygonal::Centroid | ( | ) | const |
Compute the centroid of the polygon.
Note that the centroid is not the same as the barycenter.
Box Polygonal::GetBox | ( | ) | const |
Compute the bounding box.
The polygon should have some vertices, otherwise the result is undefined.
Vector Polygonal::NormalAtLength | ( | const double & | length | ) | const |
Return the normal at the position of the point on the polygon.
length | Given length from the starting point. |
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:
Vector Polygonal::PointAtLength | ( | const double & | length | ) | const |
Return the position of the point on the polygon at a given length from the starting point.
length | Distance 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. |
void Polygonal::Rotate | ( | const Matrix & | r | ) |
Rotate the polygon.
r | Rotation matrix. |
void Polygonal::Scale | ( | const double & | s | ) |
Scale the polygon by a given factor.
s | Scaling factor. |
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.
void Polygonal::Translate | ( | const Vector & | t | ) |
Translate the polygon by a given vector.
t | Vector. |
|
friend |
Overloaded stream operator.
s | Stream. |
p | Polygon. |