Skip to content

Polygon

Polygon(vertices, holes=None)

Polygonal geometric object.

Args

  • vertices (Sequence[Sequence[float] | complex]): Vertices of the exterior boundary of the polygon.
  • holes (Sequence[Sequence[Sequence[float] | complex]] | None): Sequence of boundaries representing holes in the polygon.

Examples

>>> polygon1 = pf.Polygon([(0, 0), (1, 0), (1, 1.5), (0, 1)])
>>> boundary = [(-1, -2), (3, -2), (3, 2), (-1, 2)]
>>> hole1 = [(0, 0), (0, 1), (1, 1)]
>>> hole2 = [(0, -1), (2, -1), (2, 1)]
>>> polygon2 = pf.Polygon(boundary, [hole1, hole2])
MethodDescription
add_gds_propertyAdd a custom property to this object compatible with GDSII files.
areaStructure area.
boundsCalculate the structure bounds
copyCreate a copy of this structure.
filletRound all corners of this polygon with circular arcs.
mirrorMirror this structure.
perimeterStructure perimeter.
remove_collinearRemove internal vertices from straight segments in the polygon contours.
rotateRotate this structure.
scaleScale this structure.
to_polygonCreate a Polygon from this structure.
transformApply a transformation to this structure:
translateTranslate this structure.

add_gds_property(attribute, value)

Add a custom property to this object compatible with GDSII files.

Args

  • attribute (int): Property number.
  • value (str): Property value.

area(self)

Structure area.

Returns

float: Area of the structure.

bounds(self)

Calculate the structure bounds

Returns

tuple[ndarray, ndarray]: The lower-left and upper-right corners of the bounding box of the structure: ((min_x, min_y), (max_x, max_y)).

Example

>>> polygon = pf.Polygon([(0, 1), (1, 2), (3, -1)])
>>> bounds = polygon.bounds()
>>> print(bounds)
(array([ 0., -1.]), array([3., 2.]))

copy(self)

Create a copy of this structure.

Returns

Polygon: New copy.

fillet(self, radius)

Round all corners of this polygon with circular arcs.

Each corner is replaced by an arc of the given radius. If an adjacent edge is shorter than twice the radius, the radius is reduced to half that edge length for that corner.

Args

  • radius (float): Fillet radius.

Returns

Polygon: This polygon.

mirror(self, axis_endpoint=(1, 0), axis_origin=(0, 0))

Mirror this structure.

Args

  • axis_endpoint (Sequence[float] | complex): Mirror axis endpoint.
  • axis_origin (Sequence[float] | complex): Mirror axis origin.

Returns

Polygon: This object.

perimeter(self)

Structure perimeter.

Returns

float: Perimeter of the structure.

remove_collinear(self)

Remove internal vertices from straight segments in the polygon contours.

Returns

Polygon: This polygon.

rotate(self, rotation, center=(0, 0))

Rotate this structure.

Args

  • rotation (float): Rotation angle (in degrees).
  • center (Sequence[float, float] | complex): Center of rotation.

Returns

Polygon: This object.

scale(self, scaling, center=(0, 0))

Scale this structure.

Args

  • scaling (float): Magnification factor.
  • center (Sequence[float, float] | complex): Center of scaling.

Returns

Polygon: This object.

to_polygon(self)

Create a Polygon from this structure.

Returns

Polygon: New polygon instance.

Examples

>>> rectangle = pf.Rectangle((0, 0), (2, 1), rotation=45)
>>> polygon = rectangle.to_polygon()
>>> circle = pf.Circle(5, (0, 0), inner_radius=3)
>>> polygon = circle.to_polygon()
>>> path = pf.Path((0, 0), 0.5).s_bend((10, 2))
>>> polygon = path.to_polygon()

transform(
self, translation=(0, 0), rotation=0, scaling=1, x_reflection=False
)

Apply a transformation to this structure: self = translate(rotate(mirror(scale(self))))

Args

  • translation (Sequence[float, float] | complex): Translation vector.
  • rotation (float): Rotation angle (in degrees).
  • scaling (float): Magnification factor.
  • x_reflection (bool): Mirror across the horizontal axis.

Returns

Polygon: This object.

translate(self, translation)

Translate this structure.

Args

  • translation (Sequence[float, float] | complex): Translation vector.

Returns

Polygon: This object.

AttributeDescription
holeslist[ndarray]: List of polygon holes (read-only).
propertiesProperties: Object properties.
verticesndarray: Vertices of the exterior boundary of the polygon (read-only).
x_maxfloat: Upper bound in the x axis.
x_midfloat: Bounding box center in the x axis.
x_minfloat: Lower bound in the x axis.
y_maxfloat: Upper bound in the y axis.
y_midfloat: Bounding box center in the y axis.
y_minfloat: Lower bound in the y axis.

list[ndarray]: List of polygon holes (read-only).

Properties: Object properties.

ndarray: Vertices of the exterior boundary of the polygon (read-only).

float: Upper bound in the x axis.

float: Bounding box center in the x axis.

float: Lower bound in the x axis.

float: Upper bound in the y axis.

float: Bounding box center in the y axis.

float: Lower bound in the y axis.