mirror of
https://github.com/3b1b/manim.git
synced 2025-11-13 15:47:49 +00:00
Separate functionality of ordinary linear interpolation from that using np.outer on arrays
This commit is contained in:
parent
773520bcd9
commit
705f1a528b
1 changed files with 12 additions and 8 deletions
|
|
@ -80,15 +80,10 @@ def partial_quadratic_bezier_points(
|
|||
|
||||
# Linear interpolation variants
|
||||
|
||||
def interpolate(start: T, end: T, alpha: float) -> T:
|
||||
|
||||
def interpolate(start: T, end: T, alpha: np.ndarray | float) -> T:
|
||||
try:
|
||||
if isinstance(alpha, float):
|
||||
return (1 - alpha) * start + alpha * end
|
||||
# Otherwise, assume alpha is a list or array, and return
|
||||
# an appropriated shaped array of all corresponding
|
||||
# interpolations
|
||||
result = np.outer(1 - alpha, start) + np.outer(alpha, end)
|
||||
return result.reshape((*np.shape(alpha), *np.shape(start)))
|
||||
return (1 - alpha) * start + alpha * end
|
||||
except TypeError:
|
||||
log.debug(f"`start` parameter with type `{type(start)}` and dtype `{start.dtype}`")
|
||||
log.debug(f"`end` parameter with type `{type(end)}` and dtype `{end.dtype}`")
|
||||
|
|
@ -97,6 +92,15 @@ def interpolate(start: T, end: T, alpha: float) -> T:
|
|||
sys.exit(2)
|
||||
|
||||
|
||||
def outer_interpolate(
|
||||
start: np.ndarray | float,
|
||||
end: np.ndarray | float,
|
||||
alpha: np.ndarray | float,
|
||||
) -> T:
|
||||
result = np.outer(1 - alpha, start) + np.outer(alpha, end)
|
||||
return result.reshape((*np.shape(alpha), *np.shape(start)))
|
||||
|
||||
|
||||
def set_array_by_interpolation(
|
||||
arr: np.ndarray,
|
||||
arr1: np.ndarray,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue