TExcelTAD
Home › Calculus Essentials › Easing, Interpolation and Smooth Curves

Easing, Interpolation and Smooth Curves

Animations in games and user interfaces are functions of time, and whether they feel smooth or jerky is a question about their derivatives. This lesson looks at linear interpolation, ease-in and ease-out curves and smoothstep through calculus: we derive smoothstep from conditions on its derivative, and derive the frame-rate-independent damping formula 1−e−kΔt1 - e^{-k\Delta t} from a differential equation.

Lerp: the straight line

Linear interpolation between aa and bb with a parameter t∈[0,1]t \in [0, 1]:

lerp⁡(a,b,t)=a+(b−a) t=(1−t) a+t b\operatorname{lerp}(a, b, t) = a + (b - a)\,t = (1 - t)\,a + t\,b

If tt grows uniformly with time, the position moves at constant speed b−ab - a. Its derivative jumps from 0 to b−ab - a at the start and back to 0 at the end: in physical terms an infinite acceleration, which the eye reads as a "snap". The practical side (inverse lerp, remap) is covered in Lerp, Inverse Lerp and Remap.

Easing functions

An easing function e(t)e(t) reshapes time before the lerp: position=lerp⁡(a,b,e(t))\text{position} = \operatorname{lerp}(a, b, e(t)), with e(0)=0e(0) = 0 and e(1)=1e(1) = 1. Its derivative e′(t)e'(t) is the relative speed of the animation.

Name e(t)e(t) e′(0)e'(0) e′(1)e'(1) Feel
linear tt 1 1 mechanical
ease-in (quadratic) t2t^2 0 2 starts gently, stops hard
ease-out (quadratic) 1−(1−t)21 - (1 - t)^2 2 0 starts fast, settles
smoothstep 3t2−2t33t^2 - 2t^3 0 0 gentle at both ends
ease-in-out (cubic) 4t34t^3 for t<12t < \frac{1}{2}, else 1−4(1−t)31 - 4(1 - t)^3 0 0 stronger version of smoothstep
smootherstep 6t5−15t4+10t36t^5 - 15t^4 + 10t^3 0 0 also zero acceleration at both ends

Ease-out is ease-in played backwards: eout(t)=1−ein(1−t)e_{\text{out}}(t) = 1 - e_{\text{in}}(1 - t). That mirror trick turns any ease-in into an ease-out.

Deriving smoothstep

Which cubic p(t)=c0+c1t+c2t2+c3t3p(t) = c_0 + c_1 t + c_2 t^2 + c_3 t^3 starts at 0, ends at 1 and has zero speed at both ends? Four conditions, four unknowns. Asking for zero acceleration at the ends as well needs a quintic, and gives smootherstep:

python · try it yourself
import sympy as sp

t = sp.symbols("t")
c = sp.symbols("c0:6")

cubic = sum(c[i] * t**i for i in range(4))
conds = [cubic.subs(t, 0), cubic.subs(t, 1) - 1,
         cubic.diff(t).subs(t, 0), cubic.diff(t).subs(t, 1)]
print("smoothstep   :", sp.expand(cubic.subs(sp.solve(conds, c[:4]))))

quintic = sum(c[i] * t**i for i in range(6))
d1, d2 = quintic.diff(t), quintic.diff(t, 2)
conds = [quintic.subs(t, 0), quintic.subs(t, 1) - 1, d1.subs(t, 0), d1.subs(t, 1),
         d2.subs(t, 0), d2.subs(t, 1)]
print("smootherstep :", sp.expand(quintic.subs(sp.solve(conds, c))))

s = 3 * t**2 - 2 * t**3
print("smoothstep' =", sp.factor(s.diff(t)), "  peak speed at t = 1/2:", s.diff(t).subs(t, sp.Rational(1, 2)))
smoothstep   : -2*t**3 + 3*t**2
smootherstep : 6*t**5 - 15*t**4 + 10*t**3
smoothstep' = -6*t*(t - 1)   peak speed at t = 1/2: 3/2

SymPy prints the highest power first. Smoothstep's speed 6t(1−t)6t(1 - t) is a parabola that peaks at 1.5 halfway: to cover the same distance in the same time with gentle ends, the middle has to be 50% faster than linear. Smoothstep is also the cubic Hermite blend with zero end tangents (cubic curves are the topic of parametric and Bézier curves), and the same polynomial appears in Perlin noise (noise) and the GLSL smoothstep() function.

Seeing the speeds

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

curves = {
    "linear": lambda t: t,
    "ease-in t²": lambda t: t**2,
    "ease-out": lambda t: 1 - (1 - t)**2,
    "smoothstep": lambda t: 3 * t**2 - 2 * t**3,
    "ease-in-out cubic": lambda t: np.where(t < 0.5, 4 * t**3, 1 - 4 * (1 - t)**3),
}
ts = np.linspace(0, 1, 201)
plt.figure(figsize=(6, 4))
h = 1e-6
for name, e in curves.items():
    plt.plot(ts, e(ts), label=name)
    speed = lambda t: (e(t + h) - e(t - h)) / (2 * h)       # central difference
    print(f"{name:18s} speed at t=0.01: {float(speed(0.01)):.3f}   t=0.5: {float(speed(0.5)):.3f}   t=0.99: {float(speed(0.99)):.3f}")
plt.xlabel("t (normalised time)"); plt.ylabel("e(t) (progress)")
plt.legend(); plt.title("Easing curves")
linear             speed at t=0.01: 1.000   t=0.5: 1.000   t=0.99: 1.000
ease-in t²         speed at t=0.01: 0.020   t=0.5: 1.000   t=0.99: 1.980
ease-out           speed at t=0.01: 1.980   t=0.5: 1.000   t=0.99: 0.020
smoothstep         speed at t=0.01: 0.059   t=0.5: 1.500   t=0.99: 0.059
ease-in-out cubic  speed at t=0.01: 0.001   t=0.5: 3.000   t=0.99: 0.001

The ends tell the story: curves whose speed is near 0 at t≈0t \approx 0 and t≈1t \approx 1 start and stop softly. The ease-in-out cubic has the fastest middle (speed 3 at t=12t = \frac{1}{2}), which makes it feel snappier than smoothstep.

Damping: easing with no fixed duration

Often there is no start and end time, only a target that may move: a camera following a player, a health bar catching up. The classic line x += (target − x) * 0.1 per frame depends on the frame rate. Write down what we actually want, a rate of approach proportional to the remaining distance:

dxdt=−k(x−target)\frac{dx}{dt} = -k(x - \text{target})

This is the first-order linear equation again (Newton's cooling in disguise). Over one frame of length Δt\Delta t, with the target held fixed, its exact solution is

x(t+Δt)=target+(x−target) e−kΔt=lerp⁡(x,target,1−e−kΔt)\begin{aligned} x(t + \Delta t) &= \text{target} + (x - \text{target})\,e^{-k\Delta t} \\ &= \operatorname{lerp}(x, \text{target}, 1 - e^{-k\Delta t}) \end{aligned}

So the correct lerp factor is α=1−e−kΔt\alpha = 1 - e^{-k\Delta t}, not a constant. Because the steps are exact solutions, composing two half-frames gives the same result as one full frame: e−kΔt/2⋅e−kΔt/2=e−kΔte^{-k\Delta t/2} \cdot e^{-k\Delta t/2} = e^{-k\Delta t}.

python · try it yourself
import math

k = 6.0                                  # "per second" rate
exact = 1 - math.exp(-k * 1.0)           # remaining after 1 s is e^(-k)
print(f"ODE solution after 1 s: x = {exact:.6f}")
for fps in [30, 60, 144]:
    dt = 1 / fps
    naive, smooth = 0.0, 0.0
    for _ in range(fps):                 # one second of frames, target = 1
        naive += (1 - naive) * 0.1
        smooth += (1 - smooth) * (1 - math.exp(-k * dt))
    print(f"{fps:3d} fps: constant 0.1 -> {naive:.6f}   1 - e^(-k dt) -> {smooth:.6f}")
ODE solution after 1 s: x = 0.997521
 30 fps: constant 0.1 -> 0.957609   1 - e^(-k dt) -> 0.997521
 60 fps: constant 0.1 -> 0.998203   1 - e^(-k dt) -> 0.997521
144 fps: constant 0.1 -> 1.000000   1 - e^(-k dt) -> 0.997521

The naive version reaches different points at different frame rates; the exponential version matches the ODE at every frame rate (up to rounding). Designers often prefer a half-life hh ("halve the distance every 0.1 s"): k=ln⁡2/hk = \ln 2 / h. See frame-rate-independent damping and smoothstep and easing for engine-ready code.

In software

  • CSS and UI toolkits: transition-timing-function: ease-in-out and cubic-bezier(...) are easing functions defined by Bézier curves; spring animations solve the second-order equation instead.
  • Shaders: smoothstep(edge0, edge1, x) softens edges in anti-aliased shapes, fog and masks.
  • Games: tweening libraries, camera follow and UI bars use easing for scripted motion and exponential damping for target-following.
  • Data and ML: exponential moving averages and the sigmoid/tanh S-curves are the same mathematics in a different setting.

Exercises

Exercise 1: Lerp and its inverse

A health bar animates from 80 to 30 with linear interpolation. What does it show at t=0.3t = 0.3? At what tt does it show 45?

Answer

65 at t=0.3t = 0.3; it shows 45 at t=0.7t = 0.7.

Solution
lerp⁡(80,30,0.3)=80+(30−80)⋅0.3=80−15=6580−50t=45  ⇒  t=35/50=0.7\begin{aligned} &\operatorname{lerp}(80, 30, 0.3) = 80 + (30 - 80) \cdot 0.3 = 80 - 15 = 65 \\ &80 - 50t = 45 \;\Rightarrow\; t = 35/50 = 0.7 \end{aligned}

Exercise 2: Speeds of smoothstep

For s(t)=3t2−2t3s(t) = 3t^2 - 2t^3, compute s(0.25)s(0.25), s′(0.25)s'(0.25) and s′′(t)s''(t). Where is the acceleration zero?

Answer

s(0.25)=0.15625s(0.25) = 0.15625, s′(0.25)=1.125s'(0.25) = 1.125, s′′(t)=6−12ts''(t) = 6 - 12t, zero at t=12t = \frac{1}{2}.

Solution
s(0.25)=3⋅0.0625−2⋅0.015625=0.1875−0.03125=0.15625s′(t)=6t−6t2  ⇒  s′(0.25)=1.5−0.375=1.125s′′(t)=6−12t  ⇒  0 at t=12 (the speed peaks there)\begin{aligned} s(0.25) &= 3 \cdot 0.0625 - 2 \cdot 0.015625 = 0.1875 - 0.03125 = 0.15625 \\ s'(t) &= 6t - 6t^2 \;\Rightarrow\; s'(0.25) = 1.5 - 0.375 = 1.125 \\ s''(t) &= 6 - 12t \;\Rightarrow\; 0 \text{ at } t = \tfrac{1}{2} \text{ (the speed peaks there)} \end{aligned}

s′′(0)=6≠0s''(0) = 6 \ne 0: smoothstep starts with a jump in acceleration, which is why smootherstep exists.

Exercise 3: From half-life to lerp factor

A camera should close half of the gap to its target every 0.2 s. What is kk, and what lerp factor should a 60 fps frame use?

Answer

k=ln⁡2/0.2≈3.466k = \ln 2 / 0.2 \approx 3.466 per second; α=1−e−k/60≈0.0561\alpha = 1 - e^{-k/60} \approx 0.0561.

Solution
e−0.2k=12  ⇒  k=ln⁡2/0.2≈3.4657α=1−e−3.4657/60=1−2−1/12≈0.0561check: 12 frames of 1/60 s=0.2 s, and (1−α)12=2−1=12 ✓\begin{aligned} &e^{-0.2k} = \tfrac{1}{2} \;\Rightarrow\; k = \ln 2 / 0.2 \approx 3.4657 \\ &\alpha = 1 - e^{-3.4657/60} = 1 - 2^{-1/12} \approx 0.0561 \\ &\text{check: 12 frames of } 1/60\ \text{s} = 0.2\ \text{s, and } (1 - \alpha)^{12} = 2^{-1} = \tfrac{1}{2} \ \checkmark \end{aligned}
python · try it yourself
import math

k = math.log(2) / 0.2
alpha = 1 - math.exp(-k / 60)
print(f"k = {k:.4f}  alpha = {alpha:.4f}  remaining after 12 frames = {(1 - alpha)**12:.4f}")
k = 3.4657  alpha = 0.0561  remaining after 12 frames = 0.5000

Exercise 4: Mirror an ease

Build an ease-out from the cubic ease-in t3t^3 and give its speed at t=0t = 0 and t=1t = 1.

Answer

e(t)=1−(1−t)3e(t) = 1 - (1 - t)^3; e′(0)=3e'(0) = 3, e′(1)=0e'(1) = 0.

Solution
eout(t)=1−ein(1−t)=1−(1−t)3eout′(t)=3(1−t)2  ⇒  3 at t=0,0 at t=1\begin{aligned} e_{\text{out}}(t) &= 1 - e_{\text{in}}(1 - t) = 1 - (1 - t)^3 \\ e_{\text{out}}'(t) &= 3(1 - t)^2 \;\Rightarrow\; 3 \text{ at } t = 0, \quad 0 \text{ at } t = 1 \end{aligned}

Test yourself

Why does smoothstep 3t2−2t33t^2 - 2t^3 start and stop softly?

  1. Its value is 0 at both ends
  2. Its derivative 6t(1−t)6t(1 - t) is 0 at t=0t = 0 and t=1t = 1
  3. It is a straight line
  4. It never reaches 1

Which lerp factor makes x = lerp(x, target, α) independent of the frame rate?

  1. α=0.1\alpha = 0.1
  2. α=k Δt\alpha = k\,\Delta t
  3. α=1−e−kΔt\alpha = 1 - e^{-k\Delta t}
  4. α=e−kΔt\alpha = e^{-k\Delta t}

How do you turn an ease-in e(t)e(t) into an ease-out?

  1. e(t)2e(t)^2
  2. 1−e(1−t)1 - e(1 - t)
  3. e(1−t)e(1 - t)
  4. 1/e(t)1 / e(t)