QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsregularpolygon.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsregularpolygon.h
3 --------------
4 begin : May 2017
5 copyright : (C) 2017 by Loîc Bartoletti
6 email : lbartoletti at tuxfamily dot org
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSREGULARPOLYGON_H
19#define QGSREGULARPOLYGON_H
20
21#include "qgis_core.h"
22#include "qgscircle.h"
23#include "qgslinestring.h"
24#include "qgspoint.h"
25#include "qgspolygon.h"
26#include "qgstriangle.h"
27
28#include <QString>
29
39class CORE_EXPORT QgsRegularPolygon
40{
41 public:
42
52
57
66 QgsRegularPolygon( const QgsPoint &center, double radius, double azimuth, unsigned int numberSides, ConstructionOption circle ) SIP_HOLDGIL;
67
75 QgsRegularPolygon( const QgsPoint &center, const QgsPoint &pt1, unsigned int numberSides, ConstructionOption circle ) SIP_HOLDGIL;
76
83 QgsRegularPolygon( const QgsPoint &pt1, const QgsPoint &pt2, unsigned int numberSides ) SIP_HOLDGIL;
84
85 bool operator ==( const QgsRegularPolygon &rp ) const SIP_HOLDGIL;
86 bool operator !=( const QgsRegularPolygon &rp ) const SIP_HOLDGIL;
87
89 bool isEmpty() const SIP_HOLDGIL;
90
95 QgsPoint center() const SIP_HOLDGIL { return mCenter; }
96
103 double radius() const SIP_HOLDGIL { return mRadius; }
104
109 QgsPoint firstVertex() const SIP_HOLDGIL { return mFirstVertex; }
110
116 double apothem() const SIP_HOLDGIL { return mRadius * std::cos( M_PI / mNumberSides ); }
117
122 unsigned int numberSides() const SIP_HOLDGIL { return mNumberSides; }
123
129 void setCenter( const QgsPoint &center ) SIP_HOLDGIL;
130
136 void setRadius( double radius ) SIP_HOLDGIL;
137
143 void setFirstVertex( const QgsPoint &firstVertex ) SIP_HOLDGIL;
144
150 void setNumberSides( unsigned int numberSides ) SIP_HOLDGIL;
151
155 QgsPointSequence points() const;
156
160 QgsPolygon *toPolygon() const SIP_FACTORY;
161
165 QgsLineString *toLineString() const SIP_FACTORY;
166
171 QgsTriangle toTriangle() const;
172
177 QVector<QgsTriangle> triangulate() const;
178
182 QgsCircle inscribedCircle() const SIP_HOLDGIL;
183
187 QgsCircle circumscribedCircle() const SIP_HOLDGIL;
188
193 QString toString( int pointPrecision = 17, int radiusPrecision = 17, int anglePrecision = 2 ) const;
194
198 double interiorAngle() const SIP_HOLDGIL;
199
203 double centralAngle() const SIP_HOLDGIL;
204
209 double area() const SIP_HOLDGIL;
210
215 double perimeter() const SIP_HOLDGIL;
216
221 double length() const SIP_HOLDGIL;
222
223 private:
224 QgsPoint mCenter;
225 QgsPoint mFirstVertex;
226 unsigned int mNumberSides = 0;
227 double mRadius = 0.0;
228
232 double apothemToRadius( double apothem, unsigned int numberSides ) const;
233
237 double interiorAngle( unsigned int nbSides ) const;
238
242 double centralAngle( unsigned int nbSides ) const;
243
244};
245
246#endif // QGSREGULARPOLYGON_H
Circle geometry type.
Definition qgscircle.h:44
Line string geometry type, with support for z-dimension and m-values.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Polygon geometry type.
Definition qgspolygon.h:33
QgsRegularPolygon()=default
Constructor for QgsRegularPolygon.
QgsPoint center() const
Returns the center point of the regular polygon.
QgsPoint firstVertex() const
Returns the first vertex (corner) of the regular polygon.
ConstructionOption
A regular polygon can be constructed inscribed in a circle or circumscribed about a circle.
@ CircumscribedCircle
Circumscribed about a circle (the radius is the distance from the center to the midpoints of the side...
@ InscribedCircle
Inscribed in a circle (the radius is the distance between the center and vertices).
double radius() const
Returns the radius.
unsigned int numberSides() const
Returns the number of sides of the regular polygon.
bool isEmpty() const
A regular polygon is empty if radius equal to 0 or number of sides < 3.
double apothem() const
Returns the apothem of the regular polygon.
Triangle geometry type.
Definition qgstriangle.h:33
#define SIP_HOLDGIL
Definition qgis_sip.h:179
#define SIP_FACTORY
Definition qgis_sip.h:84
QVector< QgsPoint > QgsPointSequence