Linear, cubic and spherical interpolation
Lerp, the equal-power crossfade, cubic Hermite interpolation between samples, and slerp along the great circle between two directions.
8 minutes read
1492 words
Contents11
Given two values and a fraction, interpolation names a value in between. Which value depends on what the two are: numbers on a line, samples of a curve, or directions. Each case has its own rule, and the wrong rule gives an answer that lies between the inputs and is still wrong.
Assumed knowledge
Arithmetic, and the sine and cosine of an angle from angles and polar form . The last two sections use the length of a vector, unit vectors and the dot product, all of which matrices and vectors builds up. The cubic section uses the derivative of a polynomial.
Ground covered
Linear interpolation between two numbers. The crossfade, and the law that holds the power constant when the two signals are unrelated. Reading a signal between its samples, and why a straight line dulls the treble. The cubic through four samples and the coefficients it needs. Why a straight line between two directions leaves the sphere, and the rule that stays on it.
Linear interpolation
Between two numbers and , the value a fraction of the way from to is
At the result is exactly , at exactly , and it moves at a steady rate between the two. The same formula works entry by entry for vectors.
Crossfades
A crossfade is equation (1) applied to two signals, with rising from 0 to 1 over some time. One signal fades out as the other fades in. For a signal that is being replaced by a slightly different version of itself, equation (1) is the whole answer.
For two unrelated signals it has a flaw. Halfway through, each is at half size. Power goes as the square of size, so each contributes a quarter of its power and the total is half. That is a dip of three decibels in the middle of the fade. The cure is to pick gains whose squares add to one.
Equation (2) is the equal-power crossfade. At both gains are , each signal contributes half the power, and the total holds. A dry and wet control on an effect is this formula with as the knob. The untreated sound and the reverberated sound are unrelated enough for the equal-power law to be the right one.
Between samples
A digital signal is known only at whole-sample positions. Delaying it by samples means reading it at a position that does not exist, so a value has to be manufactured from the neighbours. Equation (1) between the two samples on either side works, and it dulls the treble. Averaging two adjacent samples is a small low-pass filter whose strength depends on , so a delay that changes slowly makes the tone flutter. Passing a curve through four neighbours instead of a line through two removes most of that.
Cubic Hermite interpolation
Name the four samples around the target , at positions . Ask for a cubic on that passes through and , with the slope at each end matching the neighbours of that end.
Those slopes, each half the difference of the samples on either side, are the Catmull-Rom choice.1 Write . The two conditions at give and at once. The two at are two equations in and , and solving them gives the other pair.
The cubic is evaluated from the inside out, which needs three multiplications rather than six.
Take the samples and . Equation (4) gives , , and . Equation (5) then gives , a little below the straight-line value of 3. The curve bends upwards, and the chord of a curve that bends upwards lies above it.
Directions and the chord
Take two unit vectors and , which are directions rather than positions, at an angle to each other. Their linear midpoint has length
because . A straight line drawn from one tip to the other cuts through the inside of the sphere. Dividing by the length puts the point back on the sphere, and then the angle swept out is no longer proportional to . The point hurries in the middle and dawdles at the ends. Over a sweep of 120 degrees in eleven steps, the projected point advances 5.8 degrees at each end and 19.1 degrees in the middle. An even sweep would advance 12 degrees at every step. Where the direction is something a listener can hear changing, that unevenness is audible.
Spherical linear interpolation
The rule that stays on the sphere and turns at a steady rate is slerp.2
The derivation is short. The wanted point lies in the plane of and , at angle from and from , so it is some combination . Dotting that combination with and then with gives two equations, and . Solving the pair uses the identity , which is the expansion of , and returns the weights in equation (7).
Equation (7) has unit length for every . It sweeps the angle at a constant rate, reaching at fraction . It is exactly at and exactly at . What has to be guarded is in the denominator. When and are nearly the same direction that sine is nearly zero, and equation (1) followed by division by the length is used instead. The arc is then almost straight, so the substitution makes no visible difference.
Equation (7) does not care how many entries the vectors have. Two directions in six dimensions are interpolated the same way, along the great circle of the five-dimensional sphere that contains them.
Choice of rule
| between | rule | why |
|---|---|---|
| two versions of one signal | linear, equation (1) | exact at both ends, and there is no power dip to fix |
| two unrelated signals | equal-power, equation (2) | holds the total power constant |
| samples of a signal | cubic Hermite, equations (4) and (5) | keeps the treble a straight line would dull |
| two directions | spherical, equation (7) | stays on the sphere at a steady rate |
Figure sources
One script draws both figures. It evaluates equations (4), (5) and (7) directly and prints the two numbers the page quotes, so a wrong coefficient cannot reach the page unnoticed. It needs NumPy and Matplotlib.
interpolation.py
uv run --with numpy --with matplotlib python3 interpolation.py
Further reading
Linear interpolation and the forms it is written in.3
The cubic Hermite spline, and the Catmull-Rom tangents of equation (3).1
Slerp, its derivation and its use for rotations.2
-
Cubic Hermite spline. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Cubic_Hermite_spline (opens in a new tab) ↩︎ ↩︎
-
Slerp. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Slerp (opens in a new tab) ↩︎ ↩︎
-
Linear interpolation. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Linear_interpolation (opens in a new tab) ↩︎