|
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. | |
| Polygon2 (const Vector2 &, const Vector2 &, const Vector2 &) | |
| Create a triangle. | |
| Polygon2 (const Vector2 &, const Vector2 &, const Vector2 &, const Vector2 &) | |
| Create a quadrangle. | |
| Polygon2 (const QVector< Vector > &) | |
| Create a polygon. | |
| Polygon2 (const QVector< Vector2 > &) | |
| Create a polygon. | |
| Polygon2 (const QVector< Vector2 > &, const QVector< int > &) | |
| Create a polygon from a set of vertexes and a subset of indexes. | |
| Polygon2 (const Triangle2 &) | |
| Create a triangle. | |
| Polygon2 (const Box2 &) | |
| Create a polygon from a box. | |
| Polygon2 (const Hexagon2 &) | |
| Create a hexagon. | |
| Polygon2 (const Pentagon2 &) | |
| Create a pentagon. | |
| Polygon2 (const Quadrangle2 &) | |
| Create a quadrangle. | |
| Polygon2 (const Polygonal &) | |
| Create a planar polygon for a polygon. | |
| Polygon2 (const Octogon2 &) | |
| Create an octogon. | |
| Polygon2 (const IrregularOctogon2 &) | |
| Create an irregular octogon. | |
| Polygon2 (const Ellipse2 &, int=72) | |
| Create a polygon approximation of an ellipse. | |
| double | Hausdorff (const Polygon2 &, bool=false) const |
| Compute the Hausdorff distance between two polygons. | |
| Box2 | GetBox () const |
| Compute the bounding box of the polygon. | |
| Polygon2 | Scaled (const Vector2 &) const |
| Return the scaled polygon. | |
| Polygon2 | Translated (const Vector2 &) const |
| Translate the polygon by a given vector. | |
| Polygon2 | Rotated (const Matrix2 &) const |
| Rotate the polygon. | |
| Polygon2 | Transformed (const Frame2 &) const |
| Trasform the polygon. | |
| void | Translate (const Vector2 &) |
| Translate the polygon by a given vector. | |
| void | Scale (const double &) |
| Scale the polygon by a given factor. | |
| void | Rotate (const Matrix2 &) |
| Rotate the polygon. | |
| void | Append (const Vector2 &) |
| Add a vertex to the polygon. | |
| Vector2 & | Vertex (int) |
| Read write access to the i-th point. | |
| Vector2 | Vertex (int) const |
| Read only access to the i-th point. | |
| 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. | |
| int | Size () const |
| Return the number of vertices 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. | |
| Vector2 | NormalAtLength (const double &) const |
| Return the normal at the position of the point on the polygon. | |
| bool | Inside (const Vector2 &) const |
| Check if a point is inside or outside of the polygon. | |
| double | R (const Vector2 &) const |
| Compute the squared distance between a point and a polygon. | |
| double | R (const Line2 &) const |
| Compute the distance from a polygon to a line. | |
| double | Signed (const Vector2 &) const |
| Compute the signed distance between a point and a polygon. | |
| bool | Intersect (const Circle2 &) const |
| Check the intersection between the boundaty of the polygon and a circle. | |
| int | Where (const Circle2 &) const |
| Check the position of a circle againts the polygon. | |
| bool | IntersectSegment (const Segment2 &) const |
| Test if a segment intersects the polygon. | |
| double | Area () const |
| Compute the area of the polygon. | |
| double | Length () const |
| Compute the perimeter of the polygon. | |
| Vector2 | Centroid () const |
| Compute the centroid of the polygon. | |
| Vector2 | Center () const |
| Compute the barycenter of the polygon. | |
| void | Subdivide (int, QVector< Vector2 > &, QVector< int > &) const |
| Create an n-adic subdivision of a polygon. | |
| void | Expand (const double &) |
| Expand the polygon by a given distance. | |
| QPolygonF | GetQt () const |
| Convert the rectangle into a Qt polygon. | |
| void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
| Draw a polygon. | |
| Polygon2 | Resampled (const double &) const |
| Resample the edges of the polygon. | |
| Polygon2 | Collapsed (const double &) const |
| Remove the edges of the polygon whose length is below a given distance threshold. | |
| QVector< Vector2 > | Poisson (const double &, int, bool=false, Random &=Random::R239) const |
| Compute a Poisson sphere distribution inside a polygon. | |
| Vector2 | RandomInside (Random &=Random::R239) const |
| Generate a random vector inside the box. | |
| QVector< int > | EarClip () const |
| Compute a simple polygon triangulation using a ear clipping method. | |
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. | |
| static double | R (const QVector< Polygon2 > &, const Vector2 &) |
| Compute the squared distance between a point and a set of polygons. | |
Protected Member Functions | |
| double | RC (const Vector2 &) const |
| Compute the squared distance between a point and the contour of the polygon. | |
Protected Attributes | |
| QVector< Vector2 > | q |
| Array of vertices. | |
Friends | |
| std::ostream & | operator<< (std::ostream &s, const Polygon2 &p) |
| Overloaded stream operator. | |
Polygons in the plane.
The class provides range-based for loops.
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 polygon from a set of vertexes and a subset of indexes.
| p | Array of points. |
| indexes | Set of indexes. |
|
explicit |
Create a triangle.
| t | Triangle. |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
Create a planar polygon for a polygon.
| p | Array of points. |
|
explicit |
|
explicit |
|
explicit |
Create a polygon approximation of an ellipse.
| e | Ellipse. |
| n | Discretization. |
|
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.
| Polygon2 Polygon2::Collapsed | ( | const double & | e | ) | const |
Remove the edges of the polygon whose length is below a given distance threshold.
| e | Distance theshold. |
| 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.
The vertices of the polygon need to be given in trigonometric order. Moreover, this method doesn't work with auto-intersecting polygons (including polygons where one point lies on one other segment).
|
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.
| double Polygon2::Hausdorff | ( | const Polygon2 & | polygon, |
| bool | directed = false ) const |
Compute the Hausdorff distance between two polygons.
| polygon | The second polygon. |
| directed | Directed distance flag, set to true to compute the directed Hausdorff distance, false to compute the (symmetrized) maximum of directed Hausdorff distances. |
Note that the symmetrized Hausdorff distance is internally implemented as:
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::Intersect | ( | const Circle2 & | c | ) | const |
Check the intersection between the boundaty of the polygon and a circle.
Compute the signed distance between the center and the polygon.
| c | The circle. |
| 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. |
| QVector< Vector2 > Polygon2::Poisson | ( | const double & | ra, |
| int | n, | ||
| bool | border = false, | ||
| Random & | random = Random::R239 ) const |
Compute a Poisson sphere distribution inside a polygon.
This function uses a simple O(n3) dart throwing algorithm.
| ra | Radius of the sphere. |
| n | Number of candidate points. |
| border | True to add vertexes of the polygon into the set (if possible). |
| random | Random number generator. |
| 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. |
| Vector2 Polygon2::RandomInside | ( | Random & | random = Random::R239 | ) | const |
Generate a random vector inside the box.
| random | Random number generator. |
|
protected |
Compute the squared distance between a point and the contour of the polygon.
| p | Point. |
| Polygon2 Polygon2::Resampled | ( | const double & | e | ) | const |
Resample the edges of the polygon.
Generate points separated by a maximal given input distance.
| e | Distance. |
| void Polygon2::Rotate | ( | const Matrix2 & | r | ) |
Rotate the polygon.
| r | Rotation matrix. |
Rotate the polygon.
| r | Rotation matrix. |
| void Polygon2::Scale | ( | const double & | s | ) |
Scale the polygon by a given factor.
| s | Scaling factor. |
Return the scaled polygon.
| s | Scaling vector. |
| 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. |
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. |
| int Polygon2::Where | ( | const Circle2 & | c | ) | const |
Check the position of a circle againts the polygon.
| c | The circle. |
|
friend |
Overloaded stream operator.
| s | Stream. |
| p | Polygon. |