psychopy.tools.mathtools.
lerp
(v0, v1, t, out=None, dtype=None)[source]¶Linear interpolation (LERP) between two vectors/coordinates.
v0 (array_like) – Initial vector/coordinate. Can be 2D where each row is a point.
v1 (array_like) – Final vector/coordinate. Must be the same shape as v0.
t (float) – Interpolation weight factor [0, 1].
out (ndarray, optional) – Optional output array. Must be same shape and dtype as the expected output if out was not specified.
dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. If out is specified, the data type of out is used and this argument is ignored. If out is not provided, ‘float64’ is used by default.
Vector at t with same shape as v0 and v1.
ndarray
Examples
Find the coordinate of the midpoint between two vectors:
u = [0., 0., 0.]
v = [0., 0., 1.]
midpoint = lerp(u, v, 0.5) # 0.5 to interpolate half-way between points