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 from a differential equation.
Lerp: the straight line
Linear interpolation between and with a parameter :
If grows uniformly with time, the position moves at constant speed . Its derivative jumps from 0 to 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 reshapes time before the lerp: , with and . Its derivative is the relative speed of the animation.
| Name | Feel | |||
|---|---|---|---|---|
| linear | 1 | 1 | mechanical | |
| ease-in (quadratic) | 0 | 2 | starts gently, stops hard | |
| ease-out (quadratic) | 2 | 0 | starts fast, settles | |
| smoothstep | 0 | 0 | gentle at both ends | |
| ease-in-out (cubic) | for , else | 0 | 0 | stronger version of smoothstep |
| smootherstep | 0 | 0 | also zero acceleration at both ends |
Ease-out is ease-in played backwards: . That mirror trick turns any ease-in into an ease-out.
Deriving smoothstep
Which cubic 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:
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 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
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 and start and stop softly. The ease-in-out cubic has the fastest middle (speed 3 at ), 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:
This is the first-order linear equation again (Newton's cooling in disguise). Over one frame of length , with the target held fixed, its exact solution is
So the correct lerp factor is , not a constant. Because the steps are exact solutions, composing two half-frames gives the same result as one full frame: .
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 ("halve the distance every 0.1 s"): . See frame-rate-independent damping and smoothstep and easing for engine-ready code.
In software
- CSS and UI toolkits:
transition-timing-function: ease-in-outandcubic-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 ? At what does it show 45?
Answer
65 at ; it shows 45 at .
Solution
Exercise 2: Speeds of smoothstep
For , compute , and . Where is the acceleration zero?
Answer
, , , zero at .
Solution
: 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 , and what lerp factor should a 60 fps frame use?
Answer
per second; .
Solution
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 and give its speed at and .
Answer
; , .
Solution
Test yourself
Why does smoothstep start and stop softly?
- Its value is 0 at both ends
- Its derivative is 0 at and
- It is a straight line
- It never reaches 1
Which lerp factor makes x = lerp(x, target, α) independent of the frame rate?
How do you turn an ease-in into an ease-out?