Core 1.0
|
Polygons in the plane. More...
#include <polygon.h>
Public Member Functions | |
Polygon2 () | |
Create an empty polygon. | |
Polygon2 (Vector2 *, int) | |
Create a polygon given an array of points. More... | |
Polygon2 (const Vector2 &, const Vector2 &, const Vector2 &) | |
Create a triangle. More... | |
Polygon2 (const Vector2 &, const Vector2 &, const Vector2 &, const Vector2 &) | |
Create a quadrangle. More... | |
Polygon2 (const QVector< Vector > &) | |
Create a polygon. More... | |
Polygon2 (const QVector< Vector2 > &) | |
Create a polygon. More... | |
Polygon2 (const Triangle2 &) | |
Create a triangle. More... | |
Polygon2 (const Box2 &) | |
Create a polygon from a box. More... | |
Polygon2 (const Hexagon2 &) | |
Create a hexagon. More... | |
Polygon2 (const Pentagon2 &) | |
Create a pentagon. More... | |
Polygon2 (const Quadrangle2 &) | |
Create a quadrangle. More... | |
Polygon2 (const Polygonal &) | |
Create a planar polygon for a polygon. More... | |
Box2 | GetBox () const |
Compute the bounding box of the polygon. More... | |
void | Translate (const Vector2 &) |
Translate the polygon by a given vector. More... | |
void | Scale (const double &) |
Scale the polygon by a given factor. More... | |
void | Rotate (const Matrix2 &) |
Rotate the polygon. More... | |
void | Append (const Vector2 &) |
Add a vertex to the polygon. More... | |
Vector2 & | Vertex (int) |
Read write access to the i-th point. More... | |
Vector2 | Vertex (int) const |
Read only access to the i-th point. More... | |
QVector< Vector2 > | Vertices () |
Get the array of vertices. | |
const QVector< Vector2 > & | Vertices () const |
Get the array of vertices. | |
Vector2 | Edge (int) const |
Return the i-th edge, starting from the i-th vertex. More... | |
int | Size () const |
Return the number of vertices of the polygon. | |
double | Length () const |
Compute the perimeter of the polygon. | |
bool | IsConvex () const |
Check whether the polygon is convex. | |
Vector2 | PointAtLength (const double &) const |
Return the position of the point on the polygon at a given length from the starting point. More... | |
Vector2 | NormalAtLength (const double &) const |
Return the normal at the position of the point on the polygon. More... | |
bool | Inside (const Vector2 &) const |
Check if a point is inside or outside of the polygon. More... | |
double | R (const Vector2 &) const |
Compute the squared distance between a point and a polygon. More... | |
double | RC (const Vector2 &) const |
Compute the squared distance between a point and the contour of the polygon. More... | |
double | R (const Line2 &) const |
Compute the distance from a polygon to a line. More... | |
double | Signed (const Vector2 &) const |
Compute the signed distance between a point and a polygon. More... | |
bool | IntersectSegment (const Segment2 &) const |
Test if a segment intersects the polygon. More... | |
double | Area () const |
Compute the area of the polygon. | |
Vector2 | Centroid () const |
Compute the centroid of the polygon. More... | |
Vector2 | Center () const |
Compute the barycenter of the polygon. More... | |
void | Subdivide (int, QVector< Vector2 > &, QVector< int > &) const |
Create an n-adic subdivision of a polygon. More... | |
void | Expand (const double &) |
Expand the polygon by a given distance. More... | |
void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
Draw a polygon. More... | |
Polygon2 | Resampled (const double &) const |
Resample the edges of the polygon. More... | |
QVector< int > | EarClip () const |
Compute a simple polygon triangulation using a ear clipping method. More... | |
Static Public Member Functions | |
static bool | Inside (const QVector< Polygon2 > &, const Vector2 &) |
Test if a point is inside the union of a set of polygons. More... | |
static double | R (const QVector< Polygon2 > &, const Vector2 &) |
Compute the squared distance between a point and a set of polygons. More... | |
Protected Attributes | |
QVector< Vector2 > | q |
Array of vertices. | |
Friends | |
std::ostream & | operator<< (std::ostream &, const Polygon2 &) |
Overloaded stream operator. More... | |
Polygons in the plane.
Note that polygons can be non-convex or even self intersecting.
|
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. |
Create a triangle.
a,b,c | Points. |
|
explicit |
Create a quadrangle.
a,b,c,d | Points. |
|
explicit |
Create a polygon.
p | Array of points. |
|
explicit |
Create a polygon.
p | Array of points. |
|
explicit |
Create a triangle.
t | Triangle. |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
Create a planar polygon for a polygon.
p | Array of points. |
|
inline |
Add a vertex to the polygon.
p | Point. |
Vector2 Polygon2::Center | ( | ) | const |
Compute the barycenter of the polygon.
Note that the barycenter is not the same as the centroid.
Vector2 Polygon2::Centroid | ( | ) | const |
Compute the centroid of the polygon.
Note that the centroid is not the same as the barycenter.
void Polygon2::Draw | ( | QGraphicsScene & | scene, |
const QPen & | pen = QPen() , |
||
const QBrush & | brush = QBrush() |
||
) | const |
Draw a polygon.
scene | Graphics scene. |
pen | The pen. |
brush | The brush. |
QVector< int > Polygon2::EarClip | ( | ) | const |
Compute a simple polygon triangulation using a ear clipping method.
|
inline |
Return the i-th edge, starting from the i-th vertex.
i | Index. |
void Polygon2::Expand | ( | const double & | e | ) |
Expand the polygon by a given distance.
e | Expansion factor. |
Box2 Polygon2::GetBox | ( | ) | const |
Compute the bounding box of the polygon.
The polygon should have some vertices, otherwise the result is undefined.
Test if a point is inside the union of a set of polygons.
Polygons should be non-intersecting. Polygons inside others will be considered as holes.
s | Set of polygons. |
p | Point. |
bool Polygon2::Inside | ( | const Vector2 & | p | ) | const |
Check if a point is inside or outside of the polygon.
p | Point. |
bool Polygon2::IntersectSegment | ( | const Segment2 & | s | ) | const |
Test if a segment intersects the polygon.
s | Segment. |
Vector2 Polygon2::NormalAtLength | ( | const double & | length | ) | const |
Return the normal at the position of the point on the polygon.
length | Perimeter length from the starting point. |
Vector2 Polygon2::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. It should be less than the perimeter of the polygon, still a modulo operation is performed inside. |
double Polygon2::R | ( | const Line2 & | line | ) | const |
Compute the distance from a polygon to a line.
line | Line. |
Compute the squared distance between a point and a set of polygons.
p | Point. |
s | Set of polygons. |
double Polygon2::R | ( | const Vector2 & | p | ) | const |
Compute the squared distance between a point and a polygon.
p | Point. |
double Polygon2::RC | ( | const Vector2 & | p | ) | const |
Compute the squared distance between a point and the contour of the polygon.
p | Point. |
Polygon2 Polygon2::Resampled | ( | const double & | x | ) | const |
Resample the edges of the polygon.
Generate points separated by a given input distance on the edges.
x | Distance |
void Polygon2::Rotate | ( | const Matrix2 & | r | ) |
Rotate the polygon.
r | Rotation matrix. |
void Polygon2::Scale | ( | const double & | s | ) |
Scale the polygon by a given factor.
s | Scaling factor. |
double Polygon2::Signed | ( | const Vector2 & | p | ) | const |
Compute the signed distance between a point and a polygon.
p | Point. |
void Polygon2::Subdivide | ( | int | n, |
QVector< Vector2 > & | 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 Polygon2::Translate | ( | const Vector2 & | t | ) |
Translate the polygon by a given vector.
t | Vector. |
|
inline |
Read write access to the i-th point.
i | Index. |
|
inline |
Read only access to the i-th point.
i | Index. |
|
friend |
Overloaded stream operator.
s | Stream. |
p | Polygon. |