Every Future has a Founding

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 aa and bb , the value a fraction tt of the way from aa to bb is

lerp(a,b,t)=a+t(ba)=(1t)a+tb.(1) \operatorname{lerp}(a, b, t) = a + t\,(b - a) = (1 - t)\,a + t\,b. \tag{1}

At t=0t = 0 the result is exactly aa , at t=1t = 1 exactly bb , 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 tt 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.

y=cos ⁣(π2t)a+sin ⁣(π2t)b,cos2+sin2=1(2) y = \cos\!\big(\tfrac{\pi}{2}\,t\big)\,a + \sin\!\big(\tfrac{\pi}{2}\,t\big)\,b, \qquad \cos^2 + \sin^2 = 1 \tag{2}

Equation (2) is the equal-power crossfade. At t=12t = \tfrac12 both gains are 1/2=0.7071/\sqrt2 = 0.707 , each signal contributes half the power, and the total holds. A dry and wet control on an effect is this formula with tt 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 2.32.3 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 tt , 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 y1,y0,y1,y2y_{-1}, y_0, y_1, y_2 , at positions 1,0,1,2-1, 0, 1, 2 . Ask for a cubic p(μ)p(\mu) on 0μ10 \le \mu \le 1 that passes through y0y_0 and y1y_1 , with the slope at each end matching the neighbours of that end.

p(0)=y0,p(1)=y1,p(0)=12(y1y1),p(1)=12(y2y0)(3) p(0) = y_0, \qquad p(1) = y_1, \qquad p'(0) = \tfrac12\,(y_1 - y_{-1}), \qquad p'(1) = \tfrac12\,(y_2 - y_0) \tag{3}

Those slopes, each half the difference of the samples on either side, are the Catmull-Rom choice.1 Write p(μ)=c0+c1μ+c2μ2+c3μ3p(\mu) = c_0 + c_1\mu + c_2\mu^2 + c_3\mu^3 . The two conditions at μ=0\mu = 0 give c0c_0 and c1c_1 at once. The two at μ=1\mu = 1 are two equations in c2c_2 and c3c_3 , and solving them gives the other pair.

c0=y0,c1=12(y1y1),c2=y152y0+2y112y2,c3=12(y2y1)+32(y0y1)(4) c_0 = y_0, \quad c_1 = \tfrac12\,(y_1 - y_{-1}), \quad c_2 = y_{-1} - \tfrac52\,y_0 + 2\,y_1 - \tfrac12\,y_2, \quad c_3 = \tfrac12\,(y_2 - y_{-1}) + \tfrac32\,(y_0 - y_1) \tag{4}

The cubic is evaluated from the inside out, which needs three multiplications rather than six.

p(μ)=((c3μ+c2)μ+c1)μ+c0(5) p(\mu) = \big((c_3\,\mu + c_2)\,\mu + c_1\big)\,\mu + c_0 \tag{5}

Take the samples 1,2,4,81, 2, 4, 8 and μ=12\mu = \tfrac12 . Equation (4) gives c0=2c_0 = 2 , c1=1.5c_1 = 1.5 , c2=15+84=0c_2 = 1 - 5 + 8 - 4 = 0 and c3=3.53=0.5c_3 = 3.5 - 3 = 0.5 . Equation (5) then gives p=2.8125p = 2.8125 , 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.

2026-09-05T01:28:23.279655 image/svg+xml Matplotlib v3.11.1, https://matplotlib.org/
The four samples of the worked example, and the interval between the middle pair read again at a larger scale. At the halfway position the straight line reads 3 and the cubic of equations (4) and (5) reads 2.8125.

Directions and the chord

Take two unit vectors aa and bb , which are directions rather than positions, at an angle Ω\Omega to each other. Their linear midpoint 12(a+b)\tfrac12(a + b) has length

12(a+b)=cosΩ2<1,(6) \big\lVert \tfrac12 (a + b) \big\rVert = \cos\frac{\Omega}{2} < 1, \tag{6}

because a+b2=2+2cosΩ=4cos2(Ω/2)\lVert a + b \rVert^2 = 2 + 2\cos\Omega = 4\cos^2(\Omega/2) . 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 tt . 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.

2026-09-05T01:28:23.327397 image/svg+xml Matplotlib v3.11.1, https://matplotlib.org/
Eleven equal steps along the chord, pushed back onto the arc, against eleven equal steps of angle. The pushed points advance 5.8 degrees at each end of the sweep and 19.1 degrees in the middle, where an even sweep of 120 degrees advances 12 degrees at every step.

Spherical linear interpolation

The rule that stays on the sphere and turns at a steady rate is slerp.2

Ω=arccos(ab),slerp(a,b,t)=sin((1t)Ω)sinΩa+sin(tΩ)sinΩb(7) \Omega = \arccos(a \cdot b), \qquad \operatorname{slerp}(a, b, t) = \frac{\sin\big((1 - t)\,\Omega\big)}{\sin\Omega}\,a + \frac{\sin(t\,\Omega)}{\sin\Omega}\,b \tag{7}

The derivation is short. The wanted point lies in the plane of aa and bb , at angle tΩt\Omega from aa and (1t)Ω(1-t)\Omega from bb , so it is some combination αa+βb\alpha a + \beta b . Dotting that combination with aa and then with bb gives two equations, α+βcosΩ=cos(tΩ)\alpha + \beta\cos\Omega = \cos(t\Omega) and αcosΩ+β=cos((1t)Ω)\alpha\cos\Omega + \beta = \cos((1-t)\Omega) . Solving the pair uses the identity cos(tΩ)cosΩcos((1t)Ω)=sinΩsin((1t)Ω)\cos(t\Omega) - \cos\Omega\cos((1-t)\Omega) = \sin\Omega\,\sin((1-t)\Omega) , which is the expansion of cos(Ω(1t)Ω)\cos(\Omega - (1-t)\Omega) , and returns the weights in equation (7).

Equation (7) has unit length for every tt . It sweeps the angle at a constant rate, reaching tΩt\Omega at fraction tt . It is exactly aa at t=0t = 0 and exactly bb at t=1t = 1 . What has to be guarded is sinΩ\sin\Omega in the denominator. When aa and bb 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


  1. Cubic Hermite spline. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Cubic_Hermite_spline (opens in a new tab)  ↩︎ ↩︎

  2. Slerp. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Slerp (opens in a new tab)  ↩︎ ↩︎

  3. Linear interpolation. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Linear_interpolation (opens in a new tab)  ↩︎

Tags