Math module

lerp

procedure · 3 overloadsSource

The linear interpolation a + (b - a) * t: a at t = 0, b at t = 1. t is not clamped, so values outside [0, 1] extrapolate. Works on float, float64, vectors, Matrix3 (element by element) and quaternions (a plain component interpolation that is not normalized; see nlerp and slerp).

ExampleOpen in playground ↗
assert(lerp(10.0, 20.0, 0.25) == 12.5);
assert(lerp(10.0, 20.0, 2.0) == 30);
assert(lerp(xyz(0, 0, 0), xyz(2, 4, 6), 0.5) == xyz(1, 2, 3));
lerp :: (a: float, b: float, t: float) -> float

Linear blend from a to b. Not clamped, so t outside 0..1 extrapolates.

Parameters

a: float
the result at t = 0.
b: float
the result at t = 1.
t: float
how far from a towards b.

Returns

float
lerp :: (a: float64, b: float64, t: float64) -> float64

Linear blend from a to b. Not clamped, so t outside 0..1 extrapolates.

Parameters

a: float64
the result at t = 0.
b: float64
the result at t = 1.
t: float64
how far from a towards b.

Returns

float64
lerp :: (a: $R, b: R, t: float) -> R

Linear blend from a to b for any type that supports +, - and * by a float.

Parameters

a: $R
the result at t = 0.
b: R
the result at t = 1.
t: float
how far from a towards b.

Returns

R

See also