From a straight line to remap, line by line
Step 1 — write the blend. Start at a and walk a
fraction t of the way toward b. The gap to
cover is (b - a), so:
\operatorname{lerp}(a, b, t) = a + (b - a)\,t.
Step 2 — check the endpoints. At t = 0 the second term
vanishes and we get a; at t = 1 we get
a + (b - a) = b. Exactly the start and exactly the end — no rounding
drift, ever.
Step 3 — the symmetric "weighted average" form. Expand and regroup the same
expression:
a + (b - a)\,t = a - a\,t + b\,t = (1 - t)\,a + t\,b.
This is lerp as a weighted average: weight (1 - t) on
the start, weight t on the end, and the two weights always sum to
1. Both forms are identical; engines tend to ship the first (one
multiply) and mathematicians prefer the second (the symmetry is obvious).
Step 4 — run it backwards: inverse lerp. Forward lerp asks "given
t, what value?". The reverse asks "given a value
v, what fraction of the way is it?". Solve
v = a + (b - a)\,t for t:
\operatorname{invlerp}(a, b, v) = \frac{v - a}{\,b - a\,}.
At v = a this is 0, at
v = b it is 1 — the perfect undo of Step 1.
(It needs a \ne b, or you would divide by a zero-width range.)
Step 5 — chain them into remap. To move a value v from
one range [a, b] into another [c, d], first
find its fraction in the source with inverse lerp, then play that fraction forward in the
destination with lerp:
\operatorname{remap}(a, b, c, d, v) = \operatorname{lerp}\big(c,\, d,\, \operatorname{invlerp}(a, b, v)\big) = c + (d - c)\,\frac{v - a}{\,b - a\,}.
That single line maps a joystick's [-1, 1] to a turret's
[0^\circ, 90^\circ], or a noise value's [0, 1] to
a terrain height — it is inverse-lerp composed with lerp, nothing more.
Step 6 — clamp so you don't overshoot. Nothing in the algebra stops
t from leaving [0, 1]: a
t = 1.4 extrapolates past b, which can
push a health bar past full or a colour out of gamut. Pin t to the
legal range first:
\operatorname{clamp}(t) = \min\big(1,\, \max(0,\, t)\big),
then lerp with the clamped value. Want the smooth-start, smooth-stop version? Reshape that clamped
t before blending — that is the very next page,
smoothstep & easing.
For a parameter t and values a, b, c, d, v:
-
Lerp blends start to end:
\operatorname{lerp}(a, b, t) = a + (b - a)\,t = (1 - t)\,a + t\,b, with
\operatorname{lerp}(a, b, 0) = a and
\operatorname{lerp}(a, b, 1) = b.
-
Inverse lerp recovers the fraction:
\operatorname{invlerp}(a, b, v) = \dfrac{v - a}{b - a} (requires
a \ne b).
-
Remap is lerp composed with inverse lerp:
\operatorname{remap}(a, b, c, d, v) = c + (d - c)\,\dfrac{v - a}{b - a}.
-
Clamp t to [0, 1] to
interpolate without extrapolating past the endpoints.
-
It works on anything you can scale and add — numbers, positions, vectors,
colours — because every form is built only from + and scalar
multiplication.
Lerp blends anything you can scale and add — and a position qualifies, so lerping the
point on a segment from A to B just lerps each
coordinate. But an orientation does not live in a flat space: blending two rotations by
straight component lerp drifts off the unit sphere and changes speed mid-turn. The fix is
SLERP,
spherical linear interpolation, which walks the great-circle arc at constant angular speed. Same
idea — a steady blend from one thing to another — but on a curved space rather than a line. Lerp is
the flat-world special case; SLERP is what you reach for the moment "the thing" is a rotation.