fibomat.shapes.arc_spline module#

Provides the ArcSpline and ArcSplineCompatible classes.

class fibomat.shapes.arc_spline.ArcSplineCompatible(*args, **kwargs)[source]#

Bases: Protocol

Abstract class can be used to mark ArcSpline compatible shapes.

to_arc_spline() ArcSpline[source]#

Transform shape to ArcSpline.

Returns:

ArcSpline

__init__(*args, **kwargs)#
class fibomat.shapes.arc_spline.ArcSpline(arc_spline: ArcSpline | ndarray, is_closed: bool | None = None, description: str | None = None)[source]#

Bases: Shape, ArcSplineCompatible

Class represents a spline containing circular arcs and straight line segments. The spline is C^0, hence, continuous but not differentiable.

__init__(arc_spline: ArcSpline | ndarray, is_closed: bool | None = None, description: str | None = None)[source]#
Args:
arc_spline (_libfibomat.ArcSpline, np.ndarray):

np.ndarray must have shape = (-1, 3) where each point is given by (x, y, bulge).

is_closed (bool, optional):

if True, the last and first point are connected (potentially with an arc, if the bulge value of the last vertex is nonzero). if False, the bulge value of the last point is ignored. The argumetn must be given if arc_spline is np.ndarray and is ignored if arc_spline is _libfibomat.ArcSpline.

description (str, optional): description

Raises:

ValueError: Raised if arc_spline is np.ndarray but is_closed not given.

classmethod from_segments(segments: Iterable[ArcSplineCompatible], description: str | None = None)[source]#

Build an ArcSpline from connected segments.

Args:
segments (Iterable[ArcSplineCompatible]):

segments. the start and end point of to consecutive segments must be equal. If this also holds for the last and first segment, the curve ist closed.

description (str, optional): description.

Returns:

ArcSpline

Raises:

RuntimeError: Raised if segments are not connected.

classmethod from_shape(segment: ArcSplineCompatible)[source]#

Converts a single segment to an ArcSpline.

Args:

segment (ArcSplineCompatible): segment.

Returns:

ArcSpline

property is_closed: bool#

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

Access:

get

to_arc_spline() ArcSpline[source]#

Transform shape to ArcSpline.

Returns:

ArcSpline

clone() ArcSpline[source]#

Create a deepcopy of the object.

Returns:

Describable

clone_with_new_description(description: str | None = None)[source]#

Similar to ArcSpline.clone() but set the description the passed description.

Args:

description (str, optional): description.

Returns:

ArcSpline

property bounding_box: BoundingBox#

BoundingBox: bounding box of transformable

Access:

get

property center: Vector#

center of the (geometric) object

Access:

get

Returns:

Any

property start: Vector#

Start point curve

Access:

get

Returns:

Vector

property end: Vector#

End point curve

Access:

get

Returns:

Vector

property vertices: ndarray#

Curve vertices.

Access:

get

Returns:

np.ndarray

property segments: Sequence[ArcSplineCompatible]#

Return a list of Line and Arc elements representing the curve.

Note

This method is not bijective with regard to the added shapes. E.g. if the curve was constructed from a Circle, this method will not return a Circle element but two Arcs.

Access:

get

Returns:

List[shape.Shape]

property arc_spline_impl: ArcSpline#
property orientation: bool#

Orientation of curve. True if curve is counterclockwise.

Note

This property is only defined for closed curves.

Access:

get

Returns:

bool

property length: float#

Length of curve.

Access:

get

Returns:

float

contains(pos: Vector | Iterable[float])[source]#
closest_point(pos: Vector | Iterable[float]) Dict[source]#
unit_tangents(i_vertex: int) Tuple[Vector | None, Vector | None][source]#

Unit tangents at vertex i_vertex.

Args:

i_vertex (int): vertex index

Returns:
Tuple[Optional[Vector], Optional[Vector]]:

left tangent, right tangent. If any of the two tangents does not exist, the tuple entry will be None.

Raises:

ValueError: Raised if i_vertex > #segmens.

kinks() List[int][source]#

Return kinks (non differentiable points) of the spline.

Returns:

List[int]: vertex indices of kinks.

segments_at_vertex(i_vertex: int) Tuple[Shape | None, Shape | None][source]#

Return the segments around the vertex with index i_vertex.

Args:

i_vertex: vertex index

Returns:
Tuple[Optional[Shape], Optional[Shape]]:

left and right segments. If any of the segments is not defined, the tuple entry will be None.

Raises:

ValueError: Raised if i_vertex > #segmens.

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 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

reversed()[source]#

Return a reversed copy of the arc spline

Returns:

ArcSpline

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

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