fibomat.shapes.polygon module#

Provides the Polygon class.

class fibomat.shapes.polygon.Polygon(points: List[Vector | Iterable[float]], description: str | None = None)[source]#

Bases: Polyline

2-dim polygon (closed polyline).

__init__(points: List[Vector | Iterable[float]], description: str | None = None)[source]#

Note

point[0] and point[-1] are automatically connected. Hence, point[0] != point[-1] usually.

Args:

points (VectorArrayLike): polygon points. description (str, optional): description

classmethod regular_ngon(n: int, radius: float = 1.0, circumcircle: bool = True, center: Vector | Iterable[float] | None = None, description: str | None = None)[source]#

Creates an regular polygon.

Args:

n (int): number of corners radius: cirumcircle or incircle radius circumcircle (bool): if true, radius is treated as circumcircle radius else as incircle radius center (VectorLike, optional): center of ngon, default to (0, 0) description (str, optional): description

Returns:

Polygon

Raises:

ValueError: Raised of n < 3 or radius <= 0.

property is_closed: bool#

bool: True if shape is closes. This property should not be defined for 0-dim shapes

Access:

get

property bounding_box: BoundingBox#

BoundingBox: bounding box of transformable

Access:

get

property center: Vector#

center of the (geometric) object

Access:

get

Returns:

Any

clone() T#

Create a deepcopy of the object.

Returns:

Describable

property description: str | None#

Description str.

Access:

get

Returns:

Optional[str]

mirrored(mirror_plane: VectorT) SelfT#

Return a mirrored object mirrored about mirror_plane.

Args:

mirror_plane (VectorLike): mirror plane to be used.

Returns:

TransformableBase

property n_points: int#

Number of points.

Access:

get

Returns:

int

property pivot: VectorT#

Origin of the (geometric) object. If origin is set to None, Transformable.center will be returned.

Pivot must be set to a callable function without parameters.

transformable_obj = ...
transformable_obj.pivot = lambda: return Vector(1, 2)
print(transformable_obj.pivot)  # will print Vector(1, 2)
Access:

get/set

Returns:

Vector

property points: ndarray#

Polyline points.

Access:

get

Returns:

np.ndarray

rotated(theta: float, origin: VectorT | str | None = None) SelfT#

Return a rotated copy around origin with angle theta in math. positive direction (counterclockwise).

Args:

theta (float): rotation angle in rad origin (Optional[Union[linalg.VectorLike, str]], optional):

origin of rotation. If not set, (0,0) is used as origin. If origin == ‘center’, the Transformable.center of the object will be used. The same applies for the case that origin == ‘origin’ with the Transformable.origin property. Default to None.

Returns:

TransformableBase

scaled(fac: float, origin: VectorT | str | None = None) SelfT#

Return a scale object homogeneously about origin with factor s.

Args:

fac (float): rotation angle in rad origin (Optional[Union[linalg.VectorLike, str]], optional):

origin of rotation. If not set, (0,0) is used as origin. If origin == ‘center’, the Transformable.center of the object will be used. The same applies for the case that origin == ‘origin’ with the Transformable.origin property. Default to None.

Returns:

TransformableBase

to_arc_spline() ArcSpline#

Transform shape to ArcSpline.

Returns:

ArcSpline

transformed(transformations: _TransformationBuilder[VectorT]) SelfT#
Return a transformed object. the transformation can be build by the following functions:
  • translate()

  • rotate()

  • scale()

  • mirror()

E.g.

transformable_obj.transform(translate([1, 2]) | rotate(np.pi/3) | mirror([3,4])
Args:

transformations (_TransformationBuilder): transformation

Returns:

TransformableBase

translated(trans_vec: VectorT) SelfT#

Return a translated copy of the object by trans_vec.

Args:

trans_vec (VectorLike): translation vector

Returns:

TransformableBase

translated_to(pos: VectorT) SelfT#

Return a translated copy of the object so that self.pivot == pos

Args:

pos: new position of object

Returns:

TransformableBase

with_changed_description(new_descr: str) T#

Clones the object and set the description to new_descr.

Args:

new_descr: new description

Returns:

Describable