QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
30 mNumberSides = numSides;
36 mRadius = std::fabs(
radius );
37 mFirstVertex = mCenter.
project( mRadius, azimuth );
42 mRadius = apothemToRadius( std::fabs(
radius ), numSides );
57 mNumberSides = numSides;
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 );
97 mRadius = std::fabs( hypothenuse );
103 return ( ( mCenter == rp.mCenter ) &&
104 ( mFirstVertex == rp.mFirstVertex ) &&
105 ( mNumberSides == rp.mNumberSides )
116 return ( ( mNumberSides < 3 ) ||
119 ( mCenter == mFirstVertex )
125 double azimuth = mFirstVertex.
isEmpty() ? 0 : mCenter.
azimuth( mFirstVertex );
133 mRadius = std::fabs(
radius );
134 double azimuth = mFirstVertex.
isEmpty() ? 0 : mCenter.
azimuth( mFirstVertex );
136 mFirstVertex = mCenter.
project( mRadius, azimuth );
141 double azimuth = mCenter.
azimuth( mFirstVertex );
144 mCenter = mFirstVertex.
project( mRadius, azimuth );
151 mNumberSides = numSides;
163 double azimuth = mCenter.
azimuth( mFirstVertex );
168 while ( n <= mNumberSides )
170 pts.push_back( mCenter.
project( mRadius, azimuth ) );
171 azimuth += azimuth_add;
172 if ( ( azimuth_add > 0 ) && ( azimuth > 180.0 ) )
185 std::unique_ptr<QgsPolygon> polygon(
new QgsPolygon() );
188 return polygon.release();
193 return polygon.release();
201 return ext.release();
207 ext->setPoints( pts );
208 ext->addVertex( pts.at( 0 ) );
210 return ext.release();
215 if (
isEmpty() || ( mNumberSides != 3 ) )
223 return QgsTriangle( pts.at( 0 ), pts.at( 1 ), pts.at( 2 ) );
228 QVector<QgsTriangle> l_tri;
238 while ( n < mNumberSides - 1 )
240 l_tri.append(
QgsTriangle( pts.at( n ), pts.at( n + 1 ), mCenter ) );
243 l_tri.append(
QgsTriangle( pts.at( n ), pts.at( 0 ), mCenter ) );
264 rep = QStringLiteral(
"Empty" );
266 rep = QStringLiteral(
"RegularPolygon (Center: %1, First Vertex: %2, Radius: %3, Azimuth: %4)" )
267 .arg( mCenter.
asWkt( pointPrecision ), 0,
's' )
268 .arg( mFirstVertex.
asWkt( pointPrecision ), 0,
's' )
284 return ( mRadius * mRadius * mNumberSides * std::sin(
centralAngle() * M_PI / 180.0 ) ) / 2;
294 return length() * mNumberSides;
304 return mRadius * 2 * std::sin( M_PI / mNumberSides );
307 double QgsRegularPolygon::apothemToRadius(
const double apothem,
const unsigned int numSides )
const
309 return apothem / std::cos( M_PI / numSides );
314 return ( nbSides - 2 ) * 180 / nbSides;
319 return 360.0 / nbSides;
QgsRegularPolygon() SIP_HOLDGIL=default
Constructor for QgsRegularPolygon.
QgsTriangle toTriangle() const
Returns as a triangle.
bool operator==(const QgsRegularPolygon &rp) const SIP_HOLDGIL
double distance(double x, double y) const SIP_HOLDGIL
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
double area() const SIP_HOLDGIL
Returns the area.
Point geometry type, with support for z-dimension and m-values.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
double length() const SIP_HOLDGIL
Returns the length of a side.
@ CircumscribedCircle
Circumscribed about a circle (the radius is the distance from the center to the midpoints of the side...
void setCenter(const QgsPoint ¢er) SIP_HOLDGIL
Sets the center point.
QgsPoint firstVertex() const SIP_HOLDGIL
Returns the first vertex (corner) of the regular polygon.
@ InscribedCircle
Inscribed in a circle (the radius is the distance between the center and vertices)
QVector< QgsTriangle > triangulate() const
Returns a triangulation (vertices from sides to the center) of the regular polygon.
Line string geometry type, with support for z-dimension and m-values.
QString toString(int pointPrecision=17, int radiusPrecision=17, int anglePrecision=2) const
Returns a string representation of the regular polygon.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const SIP_HOLDGIL
Returns a new point which correspond to this point projected by a specified distance with specified a...
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QgsCircle circumscribedCircle() const SIP_HOLDGIL
Returns the circumscribed circle.
double centralAngle() const SIP_HOLDGIL
Returns the measure of the central angle (the angle subtended at the center of the polygon by one of ...
QgsPointSequence points() const
Returns a list including the vertices of the regular polygon.
double perimeter() const SIP_HOLDGIL
Returns the perimeter.
QgsCircle inscribedCircle() const SIP_HOLDGIL
Returns the inscribed circle.
void setRadius(double radius) SIP_HOLDGIL
Sets the radius.
double azimuth(const QgsPoint &other) const SIP_HOLDGIL
Calculates Cartesian azimuth between this point and other one (clockwise in degree,...
void setNumberSides(unsigned int numberSides) SIP_HOLDGIL
Sets the number of sides.
double apothem() const SIP_HOLDGIL
Returns the apothem of the regular polygon.
ConstructionOption
A regular polygon can be constructed inscribed in a circle or circumscribed about a circle.
This document describes what qgis_wms supports does not support use feature geometry circle
void setFirstVertex(const QgsPoint &firstVertex) SIP_HOLDGIL
Sets the first vertex.
static QgsPoint midpoint(const QgsPoint &pt1, const QgsPoint &pt2) SIP_HOLDGIL
Returns a middle point between points pt1 and pt2.
bool isEmpty() const SIP_HOLDGIL
A regular polygon is empty if radius equal to 0 or number of sides < 3.
double radius() const SIP_HOLDGIL
Returns the radius.
QVector< QgsPoint > QgsPointSequence
Regular Polygon geometry type.
QgsPoint center() const SIP_HOLDGIL
Returns the center point of the regular polygon.
double interiorAngle() const SIP_HOLDGIL
Returns the measure of the interior angles in degrees.
bool operator!=(const QgsRegularPolygon &rp) const SIP_HOLDGIL
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
QgsLineString * toLineString() const
Returns as a linestring.
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)
QgsPolygon * toPolygon() const
Returns as a polygon.