manim.utils.bezier

Utility functions related to Bézier curves.

Functions

bezier(points)[source]

Classic implementation of a bezier curve.

Parameters

points (np.ndarray) – points defining the desired bezier curve.

Returns

function describing the bezier curve.

Return type

typing.Callable[[float], typing.Union[int, typing.Iterable]]

diag_to_matrix(l_and_u, diag)[source]

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

Parameters
  • l_and_u (Tuple[int, int]) –

  • diag (numpy.ndarray) –

Return type

numpy.ndarray

get_quadratic_approximation_of_cubic(a0, h0, h1, a1)[source]
get_smooth_cubic_bezier_handle_points(points)[source]
get_smooth_handle_points(points)[source]

Given some anchors (points), compute handles so the resulting bezier curve is smooth.

Parameters

points (np.ndarray) – Anchors.

Returns

Computed handles.

Return type

typing.Tuple[np.ndarray, np.ndarray]

integer_interpolate(start, end, alpha)[source]

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

Parameters
  • start (float) –

  • end (float) –

  • alpha (float) –

Return type

Tuple[int, float]

interpolate(start, end, alpha)[source]
Parameters
  • start (int) –

  • end (int) –

  • alpha (float) –

Return type

float

inverse_interpolate(start, end, value)[source]
Parameters
  • start (float) –

  • end (float) –

  • value (float) –

Return type

numpy.ndarray

is_closed(points)[source]
Parameters

points (Tuple[numpy.ndarray, numpy.ndarray]) –

Return type

bool

match_interpolate(new_start, new_end, old_start, old_end, old_value)[source]
Parameters
  • new_start (float) –

  • new_end (float) –

  • old_start (float) –

  • old_end (float) –

  • old_value (float) –

Return type

numpy.ndarray

mid(start, end)[source]
Parameters
  • start (float) –

  • end (float) –

Return type

float

partial_bezier_points(points, a, b)[source]

Given an array of points which define bezier curve, and two numbers 0<=a<b<=1, return an array 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.

Parameters
  • points (np.ndarray) – set of points defining the bezier curve.

  • a (float) – lower bound of the desired partial bezier curve.

  • b (float) – upper bound of the desired partial bezier curve.

Returns

Set of points defining the partial bezier curve.

Return type

np.ndarray

partial_quadratic_bezier_points(points, a, b)[source]