Polygon

class photonforge.Polygon(vertices, holes=None)

Polygonal geometric object.

Parameters:
  • vertices – Vertices of the exterior boundary of the polygon. Each element can be a pair of coordinates or a complex value.

  • holes – sequence of polygonal boundaries. Each polygonal boundary is a sequence of vertices and represents a hole in the polygon. boundary.

Examples

>>> polygon1 = 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 = Polygon(boundary, [hole1, hole2])

Methods

area()

Structure area.

bounds()

Calculate the structure bounds

copy()

Create a copy of this structure.

mirror([axis_endpoint, axis_origin])

Mirror this structure.

remove_collinear()

Remove internal vertices from straight segments in the polygon contours.

rotate(rotation[, center])

Rotate this structure.

scale(scaling[, center])

Scale this structure.

to_polygon()

Create a Polygon from this structure.

transform([translation, rotation, scaling, ...])

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

translate(translation)

Translate this structure.

Attributes

holes

List of polygon holes (read-only).

vertices

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

x_max

Upper bound in the x axis.

x_mid

Bounding box center in the x axis.

x_min

Lower bound in the x axis.

y_max

Upper bound in the y axis.

y_mid

Bounding box center in the y axis.

y_min

Lower bound in the y axis.

area()

Structure area.

Returns:

Area of the structure.

bounds()

Calculate the structure bounds

Returns:

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

Example

>>> polygon = Polygon([(0, 1), (1, 2), (3, -1)])
>>> bounds = polygon.bounds()
>>> print(bounds)
((0.0, -1.0), (3.0, 2.0))
copy()

Create a copy of this structure.

Returns:

New copy.

holes

List of polygon holes (read-only).

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

Mirror this structure.

Parameters:
  • axis_endpoint – Mirror axis endpoint.

  • axis_origin – Mirror axis origin.

Returns:

This object.

remove_collinear()

Remove internal vertices from straight segments in the polygon contours.

Returns:

This polygon.

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

Rotate this structure.

Parameters:
  • rotation – Rotation angle in degrees.

  • center – Center of rotation.

Returns:

This object.

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

Scale this structure.

Parameters:
  • scaling – Magnification factor.

  • center – Center of scaling.

Returns:

This object.

to_polygon()

Create a Polygon from this structure.

Returns:

New polygon instance.

Examples

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

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

Parameters:
  • translation – Coordinate pair used as a translation vector.

  • rotation – Rotation angle in degrees.

  • scaling – Magnification factor.

  • x_reflection – Mirror across the horizontal axis.

Returns:

This object.

translate(translation)

Translate this structure.

Parameters:

translation – Coordinate pair used as a translation vector.

Returns:

This object.

vertices

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

x_max

Upper bound in the x axis.

x_mid

Bounding box center in the x axis.

x_min

Lower bound in the x axis.

y_max

Upper bound in the y axis.

y_mid

Bounding box center in the y axis.

y_min

Lower bound in the y axis.