fibomat.shapes.parametric_curve module#
Provides the ParametricCurve class.
- class fibomat.shapes.parametric_curve.ParametricCurve(func: Callable[[ndarray], ndarray], d_func: Callable[[ndarray], ndarray], d2_func: Callable[[ndarray], ndarray], domain: Tuple[float, float], bounding_box: BoundingBox, curvature: Callable[[ndarray], ndarray] | None = None, length: Callable[[float, float], float] | None = None, description: str | None = None)[source]#
Bases:
Shape,ArcSplineCompatibleParametric curve f: [a, b] -> R^2 with f in C^inf
E.g. f(u) = (cos(u), sin(u)).
TODO: handle bounding box! TODO: Put references here (thesis + 2 papers)
- __init__(func: Callable[[ndarray], ndarray], d_func: Callable[[ndarray], ndarray], d2_func: Callable[[ndarray], ndarray], domain: Tuple[float, float], bounding_box: BoundingBox, curvature: Callable[[ndarray], ndarray] | None = None, length: Callable[[float, float], float] | None = None, description: str | None = None)[source]#
All Callables must be vectorized. Hence
func(1) should return np.array([x, y])
func([1, 2]) should return np.array([[x1, y1], [x2, y2]])
If length is not provided, it will be calculated numerically.
- Args:
func (Callable[[np.ndarray], np.ndarray]): function value of parametric curve d_func (Callable[[np.ndarray], np.ndarray]): function value of first derivative d2_func (Callable[[np.ndarray], np.ndarray]): function value of second derivative domain (Tuple[float, float]): parametric domain of curve bounding_box (BoundingBox): bounding box of curve curvature (Optional[Callable[[np.ndarray], np.ndarray]], optional): curvature of parametric curve. length (Optional[Callable[[float, float], float]], optional):
arc length of parametric curve in interval u_1, u_2
description (str, optional): description
- classmethod from_sympy_curve(curve: Curve, try_length_integration: bool = False, description: str | None = None)[source]#
Create a
ParametricCurvefrom a sympy curve. All derivatives are calculated automatically.- Args:
curve (sympy.geometry.Curve): parametric curve. try_length_integration (bool):
if True, it is attempted to solve arc length parametrization integral analytically.
description (str, optional): description
- Returns:
ParametricCurve
- to_arc_spline(rasterize_pitch: float | None = None, epsilon: float | None = None) ArcSpline[source]#
Transform shape to ArcSpline.
- Returns:
ArcSpline
- property domain: Tuple[float, float]#
Parametric domain of curve.
- Access:
get
- Returns:
Tuple[float, float]
- property is_closed: bool#
bool: True if shape is closes. This property should not be defined for 0-dim shapes
- Access:
get
- f(t: float | ndarray) ndarray[source]#
Function values of param. curve.
- Args:
t (float, np.ndarray): time points for evaluation.
- Returns:
np.ndarray
- df(t)[source]#
Function values of first derivative of param. curve.
- Args:
t (float, np.ndarray): time points for evaluation.
- Returns:
np.ndarray
- d2f(t)[source]#
Function values of second derivative of param. curve.
- Args:
t (float, np.ndarray): time points for evaluation.
- Returns:
np.ndarray
- curvature(t)[source]#
Curvature of param. curve.
- Args:
t (float, np.ndarray): time points for evaluation.
- Returns:
np.ndarray
- rasterize(pitch: float, domain: Tuple[float, float] | None = None, safety: float = 1.25, add_endpoint: bool = False) ndarray[source]#
Rasterize the param. curve equally.
- Args:
pitch (float): distance of rasteruized points on the curve. domain (Tuple[float, float], optional): parametric domain to be used. Default to self.domain. safety (float):
The upper bound of the function parameter of a point is estimated with the tangent vector t of the previous point with t_next_up = t_prev + pitch * safety / ||t||. If the function has large gradients, thesafety factor must be increased. Otherwise, t_next_up is not an upper bound anymore. Default to 1.5
- add_endpoint (bool): if True, the point at f(domain[1]) is added to the rasterized points, if the distance
to the point before is smaller than the pitch.
- Returns:
np.ndarray: function parameters (NOT function values)
- Raises:
RuntimeError: Raised if safety is to small.
- rasterize_at(pitch: float, domain: Tuple[float, float] | None = None)[source]#
Rasterize the param. curve equally.
- Args:
pitch (float): distance of rasteruized points on the curve. domain (Tuple[float, float], optional): parametric domain to be used. Default to self.domain.
- Returns:
np.ndarray: function values
- property bounding_box: BoundingBox#
BoundingBox: bounding box of transformable- Access:
get
- clone() T#
Create a deepcopy of the object.
- Returns:
Describable
- 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.centerwill 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
- 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.centerof the object will be used. The same applies for the case that origin == ‘origin’ with theTransformable.originproperty. 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.centerof the object will be used. The same applies for the case that origin == ‘origin’ with theTransformable.originproperty. 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