bezier

该部分代码来自 3b1b/manim,有待重构

class janim.utils.bezier.PathBuilder(*, start_point: Vect | None = None, points: VectArray | None = None, use_simple_quadratic_approx: bool = False)

基类:object

get() ndarray
append(points: VectArray, *, line_to_start_point=False) Self
move_to(point: Vect) Self
line_to(point: Vect) Self
conic_to(handle: Vect, point: Vect) Self
cubic_to(handle1: Vect, handle2: Vect, anchor: Vect) Self
arc_to(point: Vect, angle: float, n_components: int | None = None, threshold: float = 0.001) Self
close_path() Self
janim.utils.bezier.quadratic_bezier_points_for_arc(angle: float, start_angle: float = 0, n_components: int = 8) ndarray

得到使用二次贝塞尔曲线模拟的圆弧

janim.utils.bezier.bezier(points: Iterable[float | ndarray]) Callable[[float], float | ndarray]
janim.utils.bezier.partial_bezier_points(points: Sequence[ndarray], a: float, b: float) list[float]

Given an list of points which define a bezier curve, and two numbers 0<=a<b<=1, return an list of the same size, which describes the portion of the original bezier curve on the interval [a, b].

This algorithm is pretty nifty, and pretty dense.

janim.utils.bezier.partial_quadratic_bezier_points(points: Sequence[ndarray], a: float, b: float) list[ndarray]
janim.utils.bezier.interpolate(start: T, end: T, alpha: float) T
janim.utils.bezier.interpolate(start, end, alpha: ndarray) ndarray
janim.utils.bezier.outer_interpolate(start: ndarray | float, end: ndarray | float, alpha: ndarray | float) T
janim.utils.bezier.set_array_by_interpolation(arr: ~numpy.ndarray, arr1: ~numpy.ndarray, arr2: ~numpy.ndarray, alpha: float, interp_func: ~typing.Callable[[~numpy.ndarray, ~numpy.ndarray, float], ~numpy.ndarray] = <function interpolate>) ndarray
janim.utils.bezier.integer_interpolate(start: T, end: T, alpha: float) tuple[int, float]

alpha is a float between 0 and 1. This returns an integer between start and end (inclusive) representing appropriate interpolation between them, along with a "residue" representing a new proportion between the returned integer and the next one of the list.

For example, if start=0, end=10, alpha=0.46, This would return (4, 0.6).

janim.utils.bezier.mid(start: T, end: T) T
janim.utils.bezier.inverse_interpolate(start: T, end: T, value: T) float
janim.utils.bezier.match_interpolate(new_start: T, new_end: T, old_start: T, old_end: T, old_value: T) T
janim.utils.bezier.approx_smooth_quadratic_bezier_handles(points: Sequence[ndarray]) ndarray | list[ndarray]

Figuring out which bezier curves most smoothly connect a sequence of points.

Given three successive points, P0, P1 and P2, you can compute that by defining h = (1/4) P0 + P1 - (1/4)P2, the bezier curve defined by (P0, h, P1) will pass through the point P2.

So for a given set of four successive points, P0, P1, P2, P3, if we want to add a handle point h between P1 and P2 so that the quadratic bezier (P1, h, P2) is part of a smooth curve passing through all four points, we calculate one solution for h that would produce a parbola passing through P3, call it smooth_to_right, and another that would produce a parabola passing through P0, call it smooth_to_left, and use the midpoint between the two.

janim.utils.bezier.smooth_quadratic_path(anchors: VectArray) ndarray

Returns a path defining a smooth quadratic bezier spline through anchors.

janim.utils.bezier.get_smooth_cubic_bezier_handle_points(points: VectArray) tuple[ndarray, ndarray]
janim.utils.bezier.diag_to_matrix(l_and_u: tuple[int, int], diag: ndarray) ndarray

Converts array whose rows represent diagonal entries of a matrix into the matrix itself. See scipy.linalg.solve_banded

janim.utils.bezier.is_closed(points: Sequence[ndarray]) bool
janim.utils.bezier.get_quadratic_approximation_of_cubic(a0: Vect, h0: Vect, h1: Vect, a1: Vect) ndarray