RegularPolygonPixelRegion

class regions.RegularPolygonPixelRegion(center, nvertices, radius, angle=<Quantity 0. deg>, meta=None, visual=None)[source]

Bases: PolygonPixelRegion

A regular polygon in pixel coordinates.

Note

This class will be serialized as a generic polygon region, thus when read back in it will produce a PolygonPixelRegion object instead of a RegularPolygonPixelRegion object.

Parameters:
centerPixCoord

The position of the center of the polygon.

nverticesPixCoord

The number of polygon vertices (or sides).

radiusfloat

The distance from the center to any vertex. This is also known as the circumradius.

angleQuantity, optional

The rotation angle of the polygon, measured anti-clockwise. If set to zero (the default), the polygon will point “up” following the matplotlib.patches.RegularPolygon convention.

metaRegionMeta or dict, optional

A dictionary that stores the meta attributes of the region.

visualRegionVisual or dict, optional

A dictionary that stores the visual meta attributes of the region.

Examples

import astropy.units as u
import matplotlib.pyplot as plt
from regions import PixCoord, RegularPolygonPixelRegion

fig, ax = plt.subplots(1, 1)
center = PixCoord(x=50, y=50)
reg1 = RegularPolygonPixelRegion(center, 6, 15)
reg1.plot(edgecolor='red', lw=2)

center = PixCoord(x=25, y=25)
reg2 = RegularPolygonPixelRegion(center, 3, 15)
reg2.plot(edgecolor='green', lw=2)

center = PixCoord(x=25, y=75)
reg3 = RegularPolygonPixelRegion(center, 3, 15, angle=25*u.deg)
reg3.plot(edgecolor='orange', lw=2)

center = PixCoord(x=75, y=75)
reg4 = RegularPolygonPixelRegion(center, 8, 15)
reg4.plot(edgecolor='blue', lw=2)

center = PixCoord(x=75, y=25)
reg5 = RegularPolygonPixelRegion(center, 5, 15)
reg5.plot(edgecolor='magenta', lw=2)

ax.set_xlim(0, 100)
ax.set_ylim(0, 100)
ax.set_aspect('equal')

(Source code, png, hires.png, pdf, svg)

../_images/regions-RegularPolygonPixelRegion-1.png
Attributes:
side_lengthfloat

The side length.

inradiusfloat

The radius of the largest circle contained entirely within the polygon. This value is identical to the length of a line segment from the polygon center to the midpoint of one of its sides (known as as the apothem).

perimeterfloat

The polygon perimeter.

interior_anglefloat

The polygon interior angle, which is the angle at each vertex on the inside of the polygon.

exterior_anglefloat

The polygon exterior angle, which is an angle at each vertex on the outside of the polygon.

Attributes Summary

angle

The rotation angle measured anti-clockwise as a astropy.units.Quantity angle.

center

The center pixel position as a PixCoord.

meta

The meta attributes as a RegionMeta

nvertices

The number of polygon vertices.

radius

The distance from the center to any vertex in pixels as a float.

visual

The visual attributes as a RegionVisual.

Methods Summary

rotate(center, angle)

Rotate the region.

to_polygon()

Return a PolygonPixelRegion of this region.

Attributes Documentation

angle

The rotation angle measured anti-clockwise as a astropy.units.Quantity angle.

center

The center pixel position as a PixCoord.

meta

The meta attributes as a RegionMeta

nvertices

The number of polygon vertices.

radius

The distance from the center to any vertex in pixels as a float.

visual

The visual attributes as a RegionVisual.

Methods Documentation

rotate(center, angle)[source]

Rotate the region.

Positive angle corresponds to counter-clockwise rotation.

Parameters:
centerPixCoord

The rotation center point.

angleAngle

The rotation angle.

Returns:
regionPolygonPixelRegion

The rotated region (which is an independent copy).

to_polygon()[source]

Return a PolygonPixelRegion of this region.