TExcelTAD
Home › Calculus Essentials › Parametric and Bézier Curves

Parametric and Bézier Curves

A parametric curve gives xx and yy (and maybe zz) as separate functions of one parameter tt, often time. That lets a curve loop back on itself, go vertical or trace the same path at different speeds. Bézier curves, the smooth paths in every drawing tool, font and animation editor, are parametric curves built from repeated linear interpolation.

Curves as vector functions

Instead of y=f(x)y = f(x), write the position as a vector function of a parameter:

r(t)=⟨x(t),y(t)⟩,a≤t≤b\mathbf{r}(t) = \langle x(t), y(t) \rangle, \qquad a \le t \le b
Curve Parametric form Notes
Line through PP in direction d\mathbf{d} r(t)=P+t⋅d\mathbf{r}(t) = P + t \cdot \mathbf{d} t∈Rt \in \mathbb{R}
Circle, radius RR ⟨Rcos⁡t,Rsin⁡t⟩\langle R\cos t, R\sin t \rangle, 0≤t≤2π0 \le t \le 2\pi can't be a single y=f(x)y = f(x)
Ellipse ⟨acos⁡t,bsin⁡t⟩\langle a\cos t, b\sin t \rangle
Helix (3D) ⟨cos⁡t,sin⁡t,c⋅t⟩\langle \cos t, \sin t, c \cdot t \rangle a spring
Graph of ff ⟨t,f(t)⟩\langle t, f(t) \rangle every ordinary graph is a parametric curve

Sometimes you can eliminate the parameter. For x=2cos⁡tx = 2\cos t, y=3sin⁡ty = 3\sin t, use cos⁡2t+sin⁡2t=1\cos^2 t + \sin^2 t = 1 to get (x/2)2+(y/3)2=1(x/2)^2 + (y/3)^2 = 1, an ellipse.

Derivatives: tangents and slopes

Differentiate each component separately. The result r′(t)=⟨x′(t),y′(t)⟩\mathbf{r}'(t) = \langle x'(t), y'(t) \rangle is the tangent vector: it points along the curve in the direction of increasing tt, and its length is the speed at which the point moves. The slope of the curve follows from the chain rule:

dydx=dy/dtdx/dtwherever dxdt≠0\frac{dy}{dx} = \frac{dy/dt}{dx/dt} \qquad \text{wherever } \frac{dx}{dt} \ne 0

Where dx/dt=0dx/dt = 0 but dy/dt≠0dy/dt \ne 0 the tangent is vertical, something a function y=f(x)y = f(x) can never have.

Arc length

A short step dtdt moves the point a distance ∥r′(t)∥ dt\lVert \mathbf{r}'(t) \rVert \, dt, so the length of the curve is

L=∫ab∥r′(t)∥ dt=∫abx′(t)2+y′(t)2 dtL = \int_a^b \lVert \mathbf{r}'(t) \rVert \, dt = \int_a^b \sqrt{x'(t)^2 + y'(t)^2} \, dt

The integral rarely has a closed form, so in practice it is computed numerically, or by summing many short straight segments, which is what a game does to measure a path.

python · try it yourself
import sympy as sp

t = sp.symbols('t', positive=True)
x, y = t**2, t**3 / 3

dx, dy = sp.diff(x, t), sp.diff(y, t)
print("r'(t) =", (dx, dy))
print("dy/dx =", sp.simplify(dy / dx))
print("slope at t = 2:", (dy / dx).subs(t, 2))

speed = sp.sqrt(dx**2 + dy**2)
L = sp.integrate(sp.simplify(speed), (t, 0, 3))
print("length for 0 <= t <= 3:", sp.simplify(L), "≈", round(float(L), 4))
r'(t) = (2*t, t**2)
dy/dx = t/2
slope at t = 2: 1
length for 0 <= t <= 3: -8/3 + 13*sqrt(13)/3 ≈ 12.9574

For t>0t > 0 the speed is 4t2+t4=t4+t2\sqrt{4t^2 + t^4} = t\sqrt{4 + t^2}, which has the antiderivative 13(4+t2)3/2\frac{1}{3}(4 + t^2)^{3/2} (substitute u=4+t2u = 4 + t^2). From 0 to 3 that gives 13(1313−8)≈12.957\frac{1}{3}(13\sqrt{13} - 8) \approx 12.957, matching SymPy. (SymPy prints powers as **, so t**2 means t2t^2.)

Bézier curves

A Bézier curve is defined by control points. The curve starts at the first point, ends at the last, and is pulled toward the middle ones. A cubic Bézier with points P0,P1,P2,P3P_0, P_1, P_2, P_3 is

B(t)=(1−t)3P0+3(1−t)2tP1+3(1−t)t2P2+t3P3,0≤t≤1B(t) = (1 - t)^3 P_0 + 3(1 - t)^2 t P_1 + 3(1 - t) t^2 P_2 + t^3 P_3, \qquad 0 \le t \le 1

The four weights are the Bernstein polynomials. They are never negative and always sum to 1, so every point of the curve is a weighted average of the control points, which is why the curve stays inside their convex hull.

De Casteljau's algorithm evaluates the same curve with nothing but linear interpolation: lerp each neighbouring pair of points by tt, then lerp the results, until one point is left. It is numerically stable and is how most libraries evaluate and split Béziers.

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

P = np.array([[0.0, 0.0], [1.0, 3.0], [4.0, 3.0], [5.0, 0.0]])

def de_casteljau(points, t):
    pts = points.copy()
    while len(pts) > 1:
        pts = (1 - t) * pts[:-1] + t * pts[1:]   # lerp neighbours
    return pts[0]

def bernstein(P, t):
    return (1-t)**3 * P[0] + 3*(1-t)**2*t * P[1] + 3*(1-t)*t**2 * P[2] + t**3 * P[3]

print("t=0.5 de Casteljau:", de_casteljau(P, 0.5), " Bernstein:", bernstein(P, 0.5))

ts = np.linspace(0, 1, 101)
curve = np.array([de_casteljau(P, t) for t in ts])
plt.figure(figsize=(6, 4))
plt.plot(P[:, 0], P[:, 1], "o--", color="gray", label="control polygon")
plt.plot(curve[:, 0], curve[:, 1], lw=2, label="cubic Bézier")
plt.axis("equal"); plt.legend(); plt.title("A cubic Bézier curve")
t=0.5 de Casteljau: [2.5  2.25]  Bernstein: [2.5  2.25]

The derivative of a Bézier curve

Differentiating B(t)B(t) gives another Bézier curve, one degree lower, built from the differences of the control points:

B′(t)=3[(1−t)2(P1−P0)+2(1−t)t(P2−P1)+t2(P3−P2)]B'(t) = 3\left[(1 - t)^2 (P_1 - P_0) + 2(1 - t)t (P_2 - P_1) + t^2 (P_3 - P_2)\right]

So B′(0)=3(P1−P0)B'(0) = 3(P_1 - P_0) and B′(1)=3(P3−P2)B'(1) = 3(P_3 - P_2): the curve leaves P0P_0 heading toward P1P_1 and arrives at P3P_3 coming from P2P_2. To join two Béziers smoothly, make the last handle of one and the first handle of the next collinear, with equal lengths if you also want the speed to match (C1C^1 continuity).

python · try it yourself
import numpy as np

P = np.array([[0.0, 0.0], [1.0, 3.0], [4.0, 3.0], [5.0, 0.0]])

def B(t):
    return (1-t)**3*P[0] + 3*(1-t)**2*t*P[1] + 3*(1-t)*t**2*P[2] + t**3*P[3]

def dB(t):
    return 3*((1-t)**2*(P[1]-P[0]) + 2*(1-t)*t*(P[2]-P[1]) + t**2*(P[3]-P[2]))

h = 1e-6
for t in [0.0, 0.3, 1.0]:
    numeric = (B(min(t + h, 1)) - B(max(t - h, 0))) / (min(t + h, 1) - max(t - h, 0))
    print(f"t={t}: formula {dB(t)}, numeric {np.round(numeric, 4)}")

# arc length by summing short chords
ts = np.linspace(0, 1, 2001)
pts = np.array([B(t) for t in ts])
print("length ≈", round(float(np.sum(np.linalg.norm(np.diff(pts, axis=0), axis=1))), 4))
t=0.0: formula [3. 9.], numeric [3. 9.]
t=0.3: formula [5.52 3.6 ], numeric [5.52 3.6 ]
t=1.0: formula [ 3. -9.], numeric [ 3. -9.]
length ≈ 7.1906

In software

  • Vector graphics and fonts. SVG paths, PDF, PostScript and TrueType/OpenType outlines are chains of quadratic and cubic Béziers.
  • UI animation. CSS transition-timing-function: cubic-bezier(x1, y1, x2, y2) is a cubic Bézier from (0, 0) to (1, 1); the browser solves x(t)=timex(t) = \text{time} for tt and returns y(t)y(t) as progress. See Easing, Interpolation and Smooth Curves.
  • Games. Camera rails, roads, projectile previews and enemy paths. Moving at constant speed along a Bézier needs an arc-length table, because equal steps in tt are not equal steps in distance. See Bézier Curves and Catmull-Rom Splines.

Exercises

Exercise 1: Eliminate the parameter

Find an equation in xx and yy for x=1+tx = 1 + t, y=2t2y = 2t^2, and name the curve.

Answer

y=2(x−1)2y = 2(x - 1)^2, a parabola with vertex (1,0)(1, 0).

Solution

From x=1+tx = 1 + t we get t=x−1t = x - 1. Substitute: y=2(x−1)2y = 2(x - 1)^2.

Exercise 2: Slope and vertical tangents

For x=t3−3tx = t^3 - 3t, y=t2y = t^2, find dy/dxdy/dx at t=2t = 2 and the points where the tangent is vertical.

Answer

dy/dx=4/9dy/dx = 4/9 at t=2t = 2. Vertical tangents at t=±1t = \pm 1, the points (−2,1)(-2, 1) and (2,1)(2, 1).

Solution
dxdt=3t2−3,dydt=2tdydx=2t3t2−3;at t=2: 49vertical tangent: dxdt=0 and dydt≠0→t=±1t=1:(1−3,1)=(−2,1)t=−1:(−1+3,1)=(2,1)\begin{aligned} &\frac{dx}{dt} = 3t^2 - 3, \qquad \frac{dy}{dt} = 2t \\ &\frac{dy}{dx} = \frac{2t}{3t^2 - 3}; \qquad \text{at } t = 2{:}\ \frac{4}{9} \\ &\text{vertical tangent: } \frac{dx}{dt} = 0 \text{ and } \frac{dy}{dt} \ne 0 \quad\to\quad t = \pm 1 \\ &t = 1{:}\quad (1 - 3, 1) = (-2, 1) \\ &t = -1{:}\quad (-1 + 3, 1) = (2, 1) \end{aligned}

Exercise 3: Length of a circle arc

Use the arc length formula to find the length of r(t)=⟨3cos⁡t,3sin⁡t⟩\mathbf{r}(t) = \langle 3\cos t, 3\sin t \rangle for 0≤t≤π/20 \le t \le \pi/2.

Answer

3π/2≈4.7123\pi/2 \approx 4.712.

Solution
r′(t)=⟨−3sin⁡t,3cos⁡t⟩∥r′(t)∥=9sin⁡2t+9cos⁡2t=3L=∫0π/23 dt=3π2≈4.712\begin{aligned} \mathbf{r}'(t) &= \langle -3\sin t, 3\cos t \rangle \\ \lVert \mathbf{r}'(t) \rVert &= \sqrt{9\sin^2 t + 9\cos^2 t} = 3 \\ L &= \int_0^{\pi/2} 3 \, dt = \frac{3\pi}{2} \approx 4.712 \end{aligned}

That is a quarter of the circumference 2π⋅32\pi \cdot 3, as it should be.

Exercise 4: Quadratic Bézier by hand and in code

For the quadratic Bézier with P0=(0,0)P_0 = (0, 0), P1=(2,4)P_1 = (2, 4), P2=(4,0)P_2 = (4, 0), compute B(0.5)B(0.5) using de Casteljau by hand, then check it with code.

Answer

B(0.5)=(2,2)B(0.5) = (2, 2).

Solution
level 1: lerp⁡(P0,P1,0.5)=(1,2),lerp⁡(P1,P2,0.5)=(3,2)level 2: lerp⁡((1,2),(3,2),0.5)=(2,2)\begin{aligned} &\text{level 1: } \operatorname{lerp}(P_0, P_1, 0.5) = (1, 2), \qquad \operatorname{lerp}(P_1, P_2, 0.5) = (3, 2) \\ &\text{level 2: } \operatorname{lerp}((1, 2), (3, 2), 0.5) = (2, 2) \end{aligned}

Note that the curve's peak, y=2y = 2, is only half the control point's height of 4.

python · try it yourself
import numpy as np
pts = np.array([[0.0, 0.0], [2.0, 4.0], [4.0, 0.0]])
t = 0.5
while len(pts) > 1:
    pts = (1 - t) * pts[:-1] + t * pts[1:]
print(pts[0])
[2. 2.]

Test yourself

For a parametric curve, how is dy/dxdy/dx computed?

  1. dx/dt÷dy/dtdx/dt \div dy/dt
  2. dy/dt÷dx/dtdy/dt \div dx/dt
  3. dy/dt⋅dx/dtdy/dt \cdot dx/dt
  4. d2y/dt2d^2y/dt^2

Which statement about a cubic Bézier curve is true?

  1. It passes through all four control points
  2. Its tangent at the start points from P0P_0 toward P1P_1
  3. Its weights can be negative
  4. It is a degree-4 polynomial

What does de Casteljau's algorithm use to evaluate a Bézier curve?

  1. Repeated linear interpolation between neighbouring points
  2. Newton's method
  3. Numerical integration
  4. Matrix inversion