Class: QgsRegularPolygon

Regular Polygon geometry type.

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.

Methods

apothem

Returns the apothem of the regular polygon.

area

Returns the area.

center

Returns the center point of the regular polygon.

centralAngle

Returns the measure of the central angle (the angle subtended at the center of the polygon by one of its sides) in degrees.

circumscribedCircle

Returns the circumscribed circle

firstVertex

Returns the first vertex (corner) of the regular polygon.

inscribedCircle

Returns the inscribed circle

interiorAngle

Returns the measure of the interior angles in degrees.

isEmpty

A regular polygon is empty if radius equal to 0 or number of sides < 3

length

Returns the length of a side.

numberSides

Returns the number of sides of the regular polygon.

perimeter

Returns the perimeter.

points

Returns a list including the vertices of the regular polygon.

radius

Returns the radius.

setCenter

Sets the center point.

setFirstVertex

Sets the first vertex.

setNumberSides

Sets the number of sides.

setRadius

Sets the radius.

toLineString

Returns as a linestring.

toPolygon

Returns as a polygon.

toString

Returns a string representation of the regular polygon.

toTriangle

Returns as a triangle.

triangulate

Returns a triangulation (vertices from sides to the center) of the regular polygon.

Attributes

CircumscribedCircle

InscribedCircle

class qgis.core.QgsRegularPolygon[source]

Bases: object

__init__()

Constructor for QgsRegularPolygon.

__init__(center: QgsPoint, radius: float, azimuth: float, numberSides: int, circle: QgsRegularPolygon.ConstructionOption)

Constructs a regular polygon by center and parameters for the first vertex. An empty regular polygon is returned if numberSides < 3 or ConstructionOption isn’t valid.

Parameters:
  • center (QgsPoint) – The center of the regular polygon.

  • radius (float) – Distance from the center and the first vertex or sides (see ConstructionOption).

  • azimuth (float) – Angle in degrees started from the North to the first vertex.

  • numberSides (int) – Number of sides of the regular polygon.

  • circle (QgsRegularPolygon.ConstructionOption) – Option to create the polygon. see ConstructionOption

__init__(center: QgsPoint, pt1: QgsPoint, numberSides: int, circle: QgsRegularPolygon.ConstructionOption)

Constructs a regular polygon by center and another point.

Parameters:
  • center (QgsPoint) – The center of the regular polygon.

  • pt1 (QgsPoint) – The first vertex if the polygon is inscribed in circle or the midpoint of a side if the polygon is circumscribed about circle.

  • numberSides (int) – Number of sides of the regular polygon.

  • circle (QgsRegularPolygon.ConstructionOption) – 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).

__init__(pt1: QgsPoint, pt2: QgsPoint, numberSides: int)

Constructs a regular polygon by two points of the first side.

Parameters:
  • pt1 (QgsPoint) – The first vertex of the first side, also first vertex of the regular polygon.

  • pt2 (QgsPoint) – The second vertex of the first side.

  • numberSides (int) – Number of sides of the regular polygon.

__init__(a0: QgsRegularPolygon)
Parameters:

a0 (QgsRegularPolygon)

CircumscribedCircle = 1
class ConstructionOption

Bases: int

InscribedCircle = 0
apothem(self) float[source]

Returns the apothem of the regular polygon. The apothem is the radius of the inscribed circle.

See also

radius()

Return type:

float

area(self) float[source]

Returns the area. Returns 0 if the regular polygon is empty.

Return type:

float

center(self) QgsPoint[source]

Returns the center point of the regular polygon.

See also

setCenter()

Return type:

QgsPoint

centralAngle(self) float[source]

Returns the measure of the central angle (the angle subtended at the center of the polygon by one of its sides) in degrees.

Return type:

float

circumscribedCircle(self) QgsCircle[source]

Returns the circumscribed circle

Return type:

QgsCircle

firstVertex(self) QgsPoint[source]

Returns the first vertex (corner) of the regular polygon.

See also

setFirstVertex()

Return type:

QgsPoint

inscribedCircle(self) QgsCircle[source]

Returns the inscribed circle

Return type:

QgsCircle

interiorAngle(self) float[source]

Returns the measure of the interior angles in degrees.

Return type:

float

isEmpty(self) bool[source]

A regular polygon is empty if radius equal to 0 or number of sides < 3

Return type:

bool

length(self) float[source]

Returns the length of a side. Returns 0 if the regular polygon is empty.

Return type:

float

numberSides(self) int

Returns the number of sides of the regular polygon.

See also

setNumberSides()

Return type:

int

perimeter(self) float[source]

Returns the perimeter. Returns 0 if the regular polygon is empty.

Return type:

float

points(self) List[QgsPoint][source]

Returns a list including the vertices of the regular polygon.

Return type:

List[QgsPoint]

radius(self) float[source]

Returns the radius. This is also the radius of the circumscribing circle.

See also

apothem()

See also

setRadius()

Return type:

float

setCenter(self, center: QgsPoint)[source]

Sets the center point. Radius is unchanged. The first vertex is reprojected from the new center.

See also

center()

Parameters:

center (QgsPoint)

setFirstVertex(self, firstVertex: QgsPoint)[source]

Sets the first vertex. Radius is unchanged. The center is reprojected from the new first vertex.

See also

firstVertex()

Parameters:

firstVertex (QgsPoint)

setNumberSides(self, numberSides: int)[source]

Sets the number of sides. If numberSides < 3, the number of sides is unchanged.

See also

numberSides()

Parameters:

numberSides (int)

setRadius(self, radius: float)[source]

Sets the radius. Center is unchanged. The first vertex is reprojected from the center with the new radius.

See also

radius()

Parameters:

radius (float)

toLineString(self) QgsLineString | None[source]

Returns as a linestring.

Return type:

Optional[QgsLineString]

toPolygon(self) QgsPolygon | None[source]

Returns as a polygon.

Return type:

Optional[QgsPolygon]

toString(self, pointPrecision: int = 17, radiusPrecision: int = 17, anglePrecision: int = 2) str[source]

Returns a string representation of the regular polygon. Members will be truncated to the specified precision.

Parameters:
  • pointPrecision (int = 17)

  • radiusPrecision (int = 17)

  • anglePrecision (int = 2)

Return type:

str

toTriangle(self) QgsTriangle[source]

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.

Return type:

QgsTriangle

triangulate(self) List[QgsTriangle]

Returns a triangulation (vertices from sides to the center) of the regular polygon. An empty list is returned if the regular polygon is empty.

Return type:

List[QgsTriangle]