manimlib/utils/ 这个文件中主要实现了和贝塞尔曲线、插值有关的函数

manimlib.utils.bezier.bezier(points: Iterable[float | np.ndarray]) → Callable[[float], float | np.ndarray]
贝塞尔曲线的次数由 points 中点的个数确定

manimlib.utils.bezier.partial_bezier_points(points: Sequence[np.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.

给出贝塞尔曲线的点数组和两个 01 之间的数 ab
返回一个大小相同的数组,该数组描述原始贝塞尔曲线在间隔 [a,b] 上的部分

manimlib.utils.bezier.partial_quadratic_bezier_points(points: Sequence[np.ndarray], a: float, b: float) → list[float]
给出二阶贝塞尔曲线的点数组和两个 01 之间的数 ab
返回一个大小相同的数组,该数组描述原始二阶贝塞尔曲线在间隔 [a,b] 上的部分

manimlib.utils.bezier.interpolate(start: T, end: T, alpha: np.ndarray | float) → T


manimlib.utils.bezier.set_array_by_interpolation(arr: np.ndarray, arr1: np.ndarray, arr2: np.ndarray, alpha: float, interp_func: Callable[[np.ndarray, np.ndarray, float], np.ndarray] = <function interpolate>) → np.ndarray


manimlib.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).


manimlib.utils.bezier.mid(start: T, end: T) → T

返回 (start+end)/2,start 和 end 可以是任意类型

manimlib.utils.bezier.inverse_interpolate(start: T, end: T, value: T) → float

由插值的结果 value,返回 alpha

manimlib.utils.bezier.match_interpolate(new_start: T, new_end: T, old_start: T, old_end: T, old_value: T) → T
匹配插值,给出原插值范围 old_start, old_end 和结果 old_value
返回以相同比例,插值范围为 new_start, new_end 的插值结果

manimlib.utils.bezier.get_smooth_quadratic_bezier_handle_points(points: Sequence[np.ndarray]) → np.ndarray | list[np.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.

给出一系列锚点 points,返回经过 points 的平滑贝塞尔曲线的一系列控制点

manimlib.utils.bezier.diag_to_matrix(l_and_u: tuple, diag: numpy.ndarray) → numpy.ndarray

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

l, u 为非零下上对角线数,diag 为将以对角线形式填充的矩阵

manimlib.utils.bezier.is_closed(points: Sequence[np.ndarray]) → bool