QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <QString>
22 
23 #include "qgis_core.h"
24 #include "qgspoint.h"
25 #include "qgspolygon.h"
26 #include "qgslinestring.h"
27 #include "qgscircle.h"
28 #include "qgstriangle.h"
29 
30 
41 class CORE_EXPORT QgsRegularPolygon
42 {
43  public:
44 
50  {
52  CircumscribedCircle
53  };
54 
59 
68  QgsRegularPolygon( const QgsPoint &center, double radius, double azimuth, unsigned int numberSides, ConstructionOption circle ) SIP_HOLDGIL;
69 
77  QgsRegularPolygon( const QgsPoint &center, const QgsPoint &pt1, unsigned int numberSides, ConstructionOption circle ) SIP_HOLDGIL;
78 
85  QgsRegularPolygon( const QgsPoint &pt1, const QgsPoint &pt2, unsigned int numberSides ) SIP_HOLDGIL;
86 
87  bool operator ==( const QgsRegularPolygon &rp ) const SIP_HOLDGIL;
88  bool operator !=( const QgsRegularPolygon &rp ) const SIP_HOLDGIL;
89 
91  bool isEmpty() const SIP_HOLDGIL;
92 
97  QgsPoint center() const SIP_HOLDGIL { return mCenter; }
98 
105  double radius() const SIP_HOLDGIL { return mRadius; }
106 
111  QgsPoint firstVertex() const SIP_HOLDGIL { return mFirstVertex; }
112 
118  double apothem() const SIP_HOLDGIL { return mRadius * std::cos( M_PI / mNumberSides ); }
119 
124  unsigned int numberSides() const SIP_HOLDGIL { return mNumberSides; }
125 
131  void setCenter( const QgsPoint &center ) SIP_HOLDGIL;
132 
138  void setRadius( double radius ) SIP_HOLDGIL;
139 
145  void setFirstVertex( const QgsPoint &firstVertex ) SIP_HOLDGIL;
146 
152  void setNumberSides( unsigned int numberSides ) SIP_HOLDGIL;
153 
157  QgsPointSequence points() const;
158 
163 
167  QgsLineString *toLineString() const SIP_FACTORY;
168 
173  QgsTriangle toTriangle() const;
174 
179  QVector<QgsTriangle> triangulate() const;
180 
184  QgsCircle inscribedCircle() const SIP_HOLDGIL;
185 
189  QgsCircle circumscribedCircle() const SIP_HOLDGIL;
190 
195  QString toString( int pointPrecision = 17, int radiusPrecision = 17, int anglePrecision = 2 ) const;
196 
200  double interiorAngle() const SIP_HOLDGIL;
201 
205  double centralAngle() const SIP_HOLDGIL;
206 
211  double area() const SIP_HOLDGIL;
212 
217  double perimeter() const SIP_HOLDGIL;
218 
223  double length() const SIP_HOLDGIL;
224 
225  private:
226  QgsPoint mCenter;
227  QgsPoint mFirstVertex;
228  unsigned int mNumberSides = 0;
229  double mRadius = 0.0;
230 
234  double apothemToRadius( double apothem, unsigned int numberSides ) const;
235 
239  double interiorAngle( unsigned int nbSides ) const;
240 
244  double centralAngle( unsigned int nbSides ) const;
245 
246 };
247 
248 #endif // QGSREGULARPOLYGON_H
qgspolygon.h
QgsRegularPolygon::QgsRegularPolygon
QgsRegularPolygon() SIP_HOLDGIL=default
Constructor for QgsRegularPolygon.
QgsCircle
Circle geometry type.
Definition: qgscircle.h:44
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:34
qgslinestring.h
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsRegularPolygon::firstVertex
QgsPoint firstVertex() const SIP_HOLDGIL
Returns the first vertex (corner) of the regular polygon.
Definition: qgsregularpolygon.h:111
QgsRegularPolygon::InscribedCircle
@ InscribedCircle
Inscribed in a circle (the radius is the distance between the center and vertices)
Definition: qgsregularpolygon.h:51
qgspoint.h
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsRegularPolygon::numberSides
unsigned int numberSides() const SIP_HOLDGIL
Returns the number of sides of the regular polygon.
Definition: qgsregularpolygon.h:124
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_HOLDGIL
#define SIP_HOLDGIL
Definition: qgis_sip.h:157
QgsMeshUtils::toPolygon
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
Definition: qgstriangularmesh.cpp:509
qgscircle.h
qgstriangle.h
QgsRegularPolygon::apothem
double apothem() const SIP_HOLDGIL
Returns the apothem of the regular polygon.
Definition: qgsregularpolygon.h:118
QgsRegularPolygon::ConstructionOption
ConstructionOption
A regular polygon can be constructed inscribed in a circle or circumscribed about a circle.
Definition: qgsregularpolygon.h:50
circle
This document describes what qgis_wms supports does not support use feature geometry circle
Definition: sld_capabilities.txt:21
QgsRegularPolygon::radius
double radius() const SIP_HOLDGIL
Returns the radius.
Definition: qgsregularpolygon.h:105
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:46
QgsRegularPolygon
Regular Polygon geometry type.
Definition: qgsregularpolygon.h:42
QgsTriangle
Triangle geometry type.
Definition: qgstriangle.h:34