Polygon¶
- class photonforge.Polygon(vertices, holes=None)¶
Polygonal geometric object.
- Parameters:
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])
Methods
add_gds_property(value)Add a custom property to this object compatible with GDSII files.
area()Structure area.
bounds()Calculate the structure bounds
copy()Create a copy of this structure.
fillet(radius)Round all corners of this polygon with circular arcs.
mirror([axis_endpoint, axis_origin])Mirror this structure.
Structure perimeter.
Remove internal vertices from straight segments in the polygon contours.
rotate(rotation[, center])Rotate this structure.
scale(scaling[, center])Scale this structure.
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
List of polygon holes (read-only).
Object properties.
Vertices of the exterior boundary of the polygon (read-only).
Upper bound in the x axis.
Bounding box center in the x axis.
Lower bound in the x axis.
Upper bound in the y axis.
Bounding box center in the y axis.
Lower bound in the y axis.
- add_gds_property(value)¶
Add a custom property to this object compatible with GDSII files.
- Parameters:
attribute (int) – Property number.
value (str) – Property value.
- area()¶
Structure area.
- Returns:
Area of the structure.
- Return type:
float
- 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)).- Return type:
tuple[ndarray, ndarray]
Example
>>> polygon = pf.Polygon([(0, 1), (1, 2), (3, -1)]) >>> bounds = polygon.bounds() >>> print(bounds) (array([ 0., -1.]), array([3., 2.]))
- fillet(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.
- Parameters:
radius (float) – Fillet radius.
- Returns:
This polygon.
- Return type:
- holes¶
List of polygon holes (read-only).
- Type:
list[ndarray]
- mirror(axis_endpoint=(1, 0), axis_origin=(0, 0))¶
Mirror this structure.
- Parameters:
axis_endpoint (Sequence[float] | complex) – Mirror axis endpoint.
axis_origin (Sequence[float] | complex) – Mirror axis origin.
- Returns:
This object.
- Return type:
- perimeter()¶
Structure perimeter.
- Returns:
Perimeter of the structure.
- Return type:
float
- properties¶
Object properties.
- Type:
- remove_collinear()¶
Remove internal vertices from straight segments in the polygon contours.
- Returns:
This polygon.
- Return type:
- rotate(rotation, center=(0, 0))¶
Rotate this structure.
- Parameters:
rotation (float) – Rotation angle (in degrees).
center (Sequence[float, float] | complex) – Center of rotation.
- Returns:
This object.
- Return type:
- scale(scaling, center=(0, 0))¶
Scale this structure.
- Parameters:
scaling (float) – Magnification factor.
center (Sequence[float, float] | complex) – Center of scaling.
- Returns:
This object.
- Return type:
- to_polygon()¶
Create a Polygon from this structure.
- Returns:
New polygon instance.
- Return type:
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(translation=(0, 0), rotation=0, scaling=1, x_reflection=False)¶
Apply a transformation to this structure:
self = translate(rotate(mirror(scale(self))))- Parameters:
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:
This object.
- Return type:
- translate(translation)¶
Translate this structure.
- Parameters:
translation (Sequence[float, float] | complex) – Translation vector.
- Returns:
This object.
- Return type:
- vertices¶
Vertices of the exterior boundary of the polygon (read-only).
- Type:
ndarray
- x_max¶
Upper bound in the x axis.
- Type:
float
- x_mid¶
Bounding box center in the x axis.
- Type:
float
- x_min¶
Lower bound in the x axis.
- Type:
float
- y_max¶
Upper bound in the y axis.
- Type:
float
- y_mid¶
Bounding box center in the y axis.
- Type:
float
- y_min¶
Lower bound in the y axis.
- Type:
float