Skip to content

pymath.interpolate_linear

Daniel Flassig edited this page Jul 17, 2026 · 1 revision

Linear interpolation between two numbers or two vectors.

r = pymath.interpolate_linear(v, w, t)
Parameter Type Description
v number or vector Start value (returned for t == 0).
w number or vector End value (returned for t == 1); the same shape as v.
t number Interpolation parameter.

Return value

Type Description
r v + (w - v) * t — a number if the inputs are numbers, otherwise a new vector of the same dimension.

Notes:

  • t is not clamped: values outside [0, 1] extrapolate beyond v or w. Combine with pymath.clamp if clamping is wanted.
  • Both vectors must have the same dimension; v and w are not modified.
  • For spherical interpolation of rotations see pymath.interpolate_quat; for a smooth curve through several points see pymath.interpolate_cubic.

Example:

local x = pymath.interpolate_linear(0, 10, 0.25)
-- x == 2.5

local p = pymath.interpolate_linear({0, 0, 0}, {10, 20, 30}, 0.5)
-- p == {5, 10, 15}

-- t outside [0, 1] extrapolates
local y = pymath.interpolate_linear(0, 10, 1.5)
-- y == 15.0

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.clamp, pymath.smooth_step, pymath.interpolate_quat, pymath.interpolate_cubic

Clone this wiki locally