Core 1.0
Public Member Functions | Static Public Member Functions | List of all members
Convex2 Class Reference

Convex polygons in the plane. More...

#include <convex.h>

Inheritance diagram for Convex2:
Polygon2

Public Member Functions

 Convex2 ()
 Empty.
 
 Convex2 (Vector2 *, int)
 Create a convex polygon from an array of points. More...
 
 Convex2 (const Vector2 &, const Vector2 &, const Vector2 &)
 Create a convex polygon from three points. More...
 
 Convex2 (const QVector< Vector > &)
 Create a convex polygon. More...
 
 Convex2 (const QVector< Vector2 > &)
 Create a convex polygon. More...
 
 Convex2 (const Box2 &)
 Create a convex from a box. More...
 
 Convex2 (const Hexagon2 &)
 Create a convex from a hexagon. More...
 
 ~Convex2 ()
 Empty.
 
bool Cut (const Line2 &)
 Cut the convex polygon by a line. More...
 
bool addIntersectionBy (const Segment2 &)
 Compute the intersection between the convex polygon and a segment. More...
 
double R (const Vector2 &) const
 Compute the squared distance between a point and a convex polygon. More...
 
Vector2 Normal (const Vector2 &) const
 Compute the normal vector between a point and a convex polygon. More...
 
bool Inside (const Convex2 &) const
 Test if a convex is inside another one. More...
 
Convex2 Minkowski (const Convex2 &) const
 Straightforward implementation of the Minkowski sum of two convex. More...
 
- Public Member Functions inherited from Polygon2
 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...
 
Vector2Vertex (int)
 Read write access to the i-th point. More...
 
Vector2 Vertex (int) const
 Read only access to the i-th point. More...
 
QVector< Vector2Vertices ()
 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 Convex2 Hull (QVector< Vector2 >)
 Create the convex hull of a set of points. More...
 
static QVector< Convex2VoronoiCells (const QVector< Vector2 > &, const Box2 &)
 Create the Voronoi cells from a given set of points. More...
 
static Convex2 VoronoiCell (const QVector< Vector2 > &, const Box2 &, const Vector2 &)
 Create one Voronoi cell. More...
 
- Static Public Member Functions inherited from Polygon2
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...
 

Additional Inherited Members

- Protected Attributes inherited from Polygon2
QVector< Vector2q
 Array of vertices.
 

Detailed Description

Convex polygons in the plane.

Constructor & Destructor Documentation

◆ Convex2() [1/6]

Convex2::Convex2 ( Vector2 p,
int  n 
)
explicit

Create a convex polygon from an array of points.

See Convex2::Hull to compute the convex hull of a set of points.

Parameters
pArray of points.
nSize.

◆ Convex2() [2/6]

Convex2::Convex2 ( const Vector2 a,
const Vector2 b,
const Vector2 c 
)
explicit

Create a convex polygon from three points.

Parameters
a,b,cPoints (should be in trigonometric ordrer).

◆ Convex2() [3/6]

Convex2::Convex2 ( const QVector< Vector > &  q)
explicit

Create a convex polygon.

Note that convexity is not checked. See Convex2::Hull to compute the convex hull of a set of points.

Parameters
qArray of points defining the polygon (should be convex).

◆ Convex2() [4/6]

Convex2::Convex2 ( const QVector< Vector2 > &  q)
explicit

Create a convex polygon.

Parameters
qArray of points defining the polygon (should be convex).

◆ Convex2() [5/6]

Convex2::Convex2 ( const Box2 b)
explicit

Create a convex from a box.

Parameters
bThe box.

◆ Convex2() [6/6]

Convex2::Convex2 ( const Hexagon2 h)
explicit

Create a convex from a hexagon.

Parameters
hThe hexagon.

Member Function Documentation

◆ addIntersectionBy()

bool Convex2::addIntersectionBy ( const Segment2 s)

Compute the intersection between the convex polygon and a segment.

This function adds the points to the list of vertices of the convex polygon.

Parameters
sThe segment.

◆ Cut()

bool Convex2::Cut ( const Line2 line)

Cut the convex polygon by a line.

This function updates the convex polygon and returns true if intersection occured.

Parameters
lineThe line.

◆ Hull()

Convex2 Convex2::Hull ( QVector< Vector2 p)
static

Create the convex hull of a set of points.

Parameters
pSet of points.

◆ Inside()

bool Convex2::Inside ( const Convex2 convex) const

Test if a convex is inside another one.

Parameters
convexThe convex polygon.

◆ Minkowski()

Convex2 Convex2::Minkowski ( const Convex2 c) const

Straightforward implementation of the Minkowski sum of two convex.

Parameters
cConvex.

◆ Normal()

Vector2 Convex2::Normal ( const Vector2 p) const

Compute the normal vector between a point and a convex polygon.

Returns null vector if the point is inside the polygon.

Parameters
pPoint.

◆ R()

double Convex2::R ( const Vector2 p) const

Compute the squared distance between a point and a convex polygon.

Parameters
pPoint.

◆ VoronoiCell()

Convex2 Convex2::VoronoiCell ( const QVector< Vector2 > &  q,
const Box2 box,
const Vector2 p 
)
static

Create one Voronoi cell.

Parameters
qSet of points.
pPoint.
boxBox embedding the set of points.

◆ VoronoiCells()

QVector< Convex2 > Convex2::VoronoiCells ( const QVector< Vector2 > &  q,
const Box2 box 
)
static

Create the Voronoi cells from a given set of points.

Parameters
qSet of points.
boxBox embedding the set of points.