30 mNumberSides = numSides;
36 mRadius = std::fabs( radius );
37 mFirstVertex = mCenter.
project( mRadius, azimuth );
42 mRadius = apothemToRadius( std::fabs( radius ), numSides );
57 mNumberSides = numSides;
69 mRadius = apothemToRadius( center.
distance( pt1 ), numSides );
70 double azimuth = center.
azimuth( pt1 );
85 mNumberSides = numSides;
87 double azimuth = pt1.
azimuth( pt2 );
91 double angle = ( 180 - ( 360 / numSides ) ) / 2.0;
92 double hypothenuse = length / std::cos( angle * M_PI / 180 );
95 mCenter = pt1.
project( hypothenuse, azimuth + angle );
97 mRadius = std::fabs( hypothenuse );
103 return ( ( mCenter == rp.mCenter ) &&
104 ( mFirstVertex == rp.mFirstVertex ) &&
105 ( mNumberSides == rp.mNumberSides )
116 return ( ( mNumberSides < 3 ) ||
117 ( mCenter == mFirstVertex )
123 double azimuth = mCenter.
azimuth( mFirstVertex );
126 mFirstVertex = center.
project( mRadius, azimuth );
131 mRadius = std::fabs( radius );
132 double azimuth = mCenter.
azimuth( mFirstVertex );
134 mFirstVertex = mCenter.
project( mRadius, azimuth );
139 double azimuth = mCenter.
azimuth( mFirstVertex );
142 mCenter = mFirstVertex.
project( mRadius, azimuth );
149 mNumberSides = numSides;
161 double azimuth = mCenter.
azimuth( mFirstVertex );
166 while ( n <= mNumberSides )
168 pts.push_back( mCenter.
project( mRadius, azimuth ) );
169 azimuth += azimuth_add;
170 if ( ( azimuth_add > 0 ) && ( azimuth > 180.0 ) )
183 std::unique_ptr<QgsPolygon> polygon(
new QgsPolygon() );
186 return polygon.release();
191 return polygon.release();
199 return ext.release();
205 ext->setPoints( pts );
206 ext->addVertex( pts.at( 0 ) );
208 return ext.release();
213 if (
isEmpty() || ( mNumberSides != 3 ) )
221 return QgsTriangle( pts.at( 0 ), pts.at( 1 ), pts.at( 2 ) );
226 QVector<QgsTriangle> l_tri;
236 while ( n < mNumberSides - 1 )
238 l_tri.append(
QgsTriangle( pts.at( n ), pts.at( n + 1 ), mCenter ) );
241 l_tri.append(
QgsTriangle( pts.at( n ), pts.at( 0 ), mCenter ) );
262 rep = QStringLiteral(
"Empty" );
264 rep = QStringLiteral(
"RegularPolygon (Center: %1, First Vertex: %2, Radius: %3, Azimuth: %4)" )
265 .arg( mCenter.
asWkt( pointPrecision ), 0,
's' )
266 .arg( mFirstVertex.
asWkt( pointPrecision ), 0,
's' )
282 return ( mRadius * mRadius * mNumberSides * std::sin(
centralAngle() * M_PI / 180.0 ) ) / 2;
292 return length() * mNumberSides;
302 return mRadius * 2 * std::sin( M_PI / mNumberSides );
305 double QgsRegularPolygon::apothemToRadius(
const double apothem,
const unsigned int numSides )
const 307 return apothem / std::cos( M_PI / numSides );
312 return ( nbSides - 2 ) * 180 / nbSides;
317 return 360.0 / nbSides;
double radius() const
Returns the radius.
bool operator!=(const QgsRegularPolygon &rp) const
void setFirstVertex(const QgsPoint &firstVertex)
Sets the first vertex.
QgsPoint center() const
Returns the center point of the regular polygon.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
double azimuth(const QgsPoint &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north) ...
QVector< QgsTriangle > triangulate() const
Returns a triangulation (vertices from sides to the center) of the regular polygon.
QString toString(int pointPrecision=17, int radiusPrecision=17, int anglePrecision=2) const
Returns a string representation of the regular polygon.
QgsCircle inscribedCircle() const
Returns the inscribed circle.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
QgsCircle circumscribedCircle() const
Returns the circumscribed circle.
void setRadius(const double radius)
Sets the radius.
QgsPointSequence points() const
Returns a list including the vertices of the regular polygon.
bool isEmpty() const
A regular polygon is empty if radius equal to 0 or number of sides < 3.
double area() const
Returns the area.
static QgsPoint midpoint(const QgsPoint &pt1, const QgsPoint &pt2)
Returns a middle point between points pt1 and pt2.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
double perimeter() const
Returns the perimeter.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
Regular Polygon geometry type.
ConstructionOption
A regular polygon can be constructed inscribed in a circle or circumscribed about a circle...
QgsRegularPolygon()=default
Constructor for QgsRegularPolygon.
double length() const
Returns the length of a side.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which correspond to this point projected by a specified distance with specified a...
Point geometry type, with support for z-dimension and m-values.
double interiorAngle() const
Returns the measure of the interior angles in degrees.
QVector< QgsPoint > QgsPointSequence
void setCenter(const QgsPoint ¢er)
Sets the center point.
bool operator==(const QgsRegularPolygon &rp) const
Line string geometry type, with support for z-dimension and m-values.
void setNumberSides(const unsigned int numberSides)
Sets the number of sides.
QgsLineString * toLineString() const
Returns as a linestring.
double apothem() const
Returns the apothem of the regular polygon.
double centralAngle() const
Returns the measure of the central angle (the angle subtended at the center of the polygon by one of ...
QgsPolygon * toPolygon() const
Returns as a polygon.
QgsPoint firstVertex() const
Returns the first vertex (corner) of the regular polygon.
QgsTriangle toTriangle() const
Returns as a triangle.