QgsRegularPolygon class
Regular Polygon geometry type.
Contents
A regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length). The regular polygon is defined by a center point with a number of sides/vertices, a radius and the first vertex.
Public types
- enum ConstructionOption { InscribedCircle, CircumscribedCircle }
- A regular polygon can be constructed inscribed in a circle or circumscribed about a circle.
Constructors, destructors, conversion operators
- QgsRegularPolygon() defaulted
- Constructor for QgsRegularPolygon.
- QgsRegularPolygon(const QgsPoint& center, double radius, double azimuth, unsigned int numberSides, ConstructionOption circle)
- Constructs a regular polygon by center and parameters for the first vertex.
- QgsRegularPolygon(const QgsPoint& center, const QgsPoint& pt1, unsigned int numberSides, ConstructionOption circle)
- Constructs a regular polygon by center and another point.
- QgsRegularPolygon(const QgsPoint& pt1, const QgsPoint& pt2, unsigned int numberSides)
- Constructs a regular polygon by two points of the first side.
Public functions
- auto apothem() const -> double
- Returns the apothem of the regular polygon.
- auto area() const -> double
- Returns the area.
- auto center() const -> QgsPoint
- Returns the center point of the regular polygon.
- auto centralAngle() const -> double
- Returns the measure of the central angle (the angle subtended at the center of the polygon by one of its sides) in degrees.
- auto circumscribedCircle() const -> QgsCircle
- Returns the circumscribed circle.
- auto firstVertex() const -> QgsPoint
- Returns the first vertex (corner) of the regular polygon.
- auto inscribedCircle() const -> QgsCircle
- Returns the inscribed circle.
- auto interiorAngle() const -> double
- Returns the measure of the interior angles in degrees.
- auto isEmpty() const -> bool
- A regular polygon is empty if radius equal to 0 or number of sides < 3.
- auto length() const -> double
- Returns the length of a side.
- auto numberSides() const -> unsigned int
- Returns the number of sides of the regular polygon.
- auto perimeter() const -> double
- Returns the perimeter.
- auto points() const -> QgsPointSequence
- Returns a list including the vertices of the regular polygon.
- auto radius() const -> double
- Returns the radius.
- void setCenter(const QgsPoint& center)
- Sets the center point.
- void setFirstVertex(const QgsPoint& firstVertex)
- Sets the first vertex.
- void setNumberSides(unsigned int numberSides)
- Sets the number of sides.
- void setRadius(double radius)
- Sets the radius.
- auto toLineString() const -> QgsLineString*
- Returns as a linestring.
- auto toPolygon() const -> QgsPolygon*
- Returns as a polygon.
- auto toString(int pointPrecision = 17, int radiusPrecision = 17, int anglePrecision = 2) const -> QString
- Returns a string representation of the regular polygon.
- auto toTriangle() const -> QgsTriangle
- Returns as a triangle.
- auto triangulate() const -> QVector<QgsTriangle>
- Returns a triangulation (vertices from sides to the center) of the regular polygon.
Function documentation
QgsRegularPolygon:: QgsRegularPolygon(const QgsPoint& center,
double radius,
double azimuth,
unsigned int numberSides,
ConstructionOption circle)
Constructs a regular polygon by center and parameters for the first vertex.
| Parameters | |
|---|---|
| center | The center of the regular polygon. |
| radius | Distance from the center and the first vertex or sides (see ConstructionOption). |
| azimuth | Angle in degrees started from the North to the first vertex. |
| numberSides | Number of sides of the regular polygon. |
| circle | Option to create the polygon. |
An empty regular polygon is returned if numberSides < 3 or ConstructionOption isn't valid.
QgsRegularPolygon:: QgsRegularPolygon(const QgsPoint& center,
const QgsPoint& pt1,
unsigned int numberSides,
ConstructionOption circle)
Constructs a regular polygon by center and another point.
| Parameters | |
|---|---|
| center | The center of the regular polygon. |
| pt1 | The first vertex if the polygon is inscribed in circle or the midpoint of a side if the polygon is circumscribed about circle. |
| numberSides | Number of sides of the regular polygon. |
| circle | Option to create the polygon inscribed in circle (the radius is the distance between the center and vertices) or circumscribed about circle (the radius is the distance from the center to the midpoints of the sides). |
QgsRegularPolygon:: QgsRegularPolygon(const QgsPoint& pt1,
const QgsPoint& pt2,
unsigned int numberSides)
Constructs a regular polygon by two points of the first side.
| Parameters | |
|---|---|
| pt1 | The first vertex of the first side, also first vertex of the regular polygon. |
| pt2 | The second vertex of the first side. |
| numberSides | Number of sides of the regular polygon. |
double QgsRegularPolygon:: apothem() const
Returns the apothem of the regular polygon.
The apothem is the radius of the inscribed circle.
QgsPoint QgsRegularPolygon:: firstVertex() const
Returns the first vertex (corner) of the regular polygon.
double QgsRegularPolygon:: length() const
Returns the length of a side.
Returns 0 if the regular polygon is empty.
unsigned int QgsRegularPolygon:: numberSides() const
Returns the number of sides of the regular polygon.
double QgsRegularPolygon:: perimeter() const
Returns the perimeter.
Returns 0 if the regular polygon is empty.
double QgsRegularPolygon:: radius() const
Returns the radius.
This is also the radius of the circumscribing circle.
void QgsRegularPolygon:: setFirstVertex(const QgsPoint& firstVertex)
Sets the first vertex.
Radius is unchanged. The center is reprojected from the new first vertex.
void QgsRegularPolygon:: setNumberSides(unsigned int numberSides)
Sets the number of sides.
If numberSides < 3, the number of sides is unchanged.
void QgsRegularPolygon:: setRadius(double radius)
Sets the radius.
Center is unchanged. The first vertex is reprojected from the center with the new radius.
QString QgsRegularPolygon:: toString(int pointPrecision = 17,
int radiusPrecision = 17,
int anglePrecision = 2) const
Returns a string representation of the regular polygon.
Members will be truncated to the specified precision.
QgsTriangle QgsRegularPolygon:: toTriangle() const
Returns as a triangle.
An empty triangle is returned if the regular polygon is empty or if the number of sides is different from 3.
QVector<QgsTriangle> QgsRegularPolygon:: triangulate() const
Returns a triangulation (vertices from sides to the center) of the regular polygon.
An empty list is returned if the regular polygon is empty.