Bézier Curves by Repeated Lerp
A Bézier curve is a lerp of lerps: slide a point part of the way along each leg of the control polygon, then slide between those points and keep going until one point is left. As runs from to that last point draws a smooth curve that starts at the first control point, ends at the last and bends toward the ones in between without touching them.
What the symbols mean
- Point on the curve
Where the curve is at parameter t. As t runs from 0 to 1 it traces the whole curve.
- Lerp
lerp(A, B, t) = A + t(B − A): slide a fraction t of the way from A to B.
- Start point
The curve starts exactly here, at t = 0.
- Middle control point
Pulls the curve toward itself, but the curve doesn't pass through it.
- End point
The curve ends exactly here, at t = 1.
- Parameter
How far through the curve you are, from 0 to 1. Not the same as the fraction of the distance.
What the symbols mean
- Control points
The four points you place: P₀ and P₃ are the ends, P₁ and P₂ are the handles.
- Round-one points
Three points, one sliding along each leg of the control polygon.
- Round-two points
Two points, sliding along the segments between the Q's.
- Point on the curve
The single point left after three rounds.
Explanation
A Bézier curve is a smooth curve you steer with a few points called control points: it starts at the first one, ends at the last one and bends toward the ones in between as if they were magnets it never quite reaches. It's named after Pierre Bézier, an engineer who used these curves to design car bodies in the 1960s; Paul de Casteljau, at a rival car maker, had found the same curves a few years earlier, and the way of building them in this lesson carries his name. The whole construction is one move done over and over: lerp, (slide a fraction of the way from to ). Lerp along each leg, then lerp between the results, until one point is left. The formulas look like a pile of subscripts, but every one of them just says "slide part of the way"; bear with it.
Three points: lerp twice, then once more. Take a look at lerp from Lerp: Blending Between Two Values. It moves a point along one straight segment. Now put two segments end to end, from to and from to , and pick one value of :
- slides along the first leg.
- slides along the second leg.
- slides along the segment between them.
As grows, and both move forward, so the segment between them swings around and slides along that swinging segment. Think about why that gives a curve and not a straight line: is sliding along a ruler that is turning underneath it. At everything sits at , and at everything sits at . There's an animation further down that builds it live.
Where the formula comes from. Write each lerp as a weighted average, . Then and , and
The middle term gets a because shows up in both lerps. Each coordinate is a quadratic in , so this is a quadratic Bézier curve: a piece of a parabola, the same shape a thrown ball makes.
Four points: the cubic. Add one more point and one more round. Four control points give three legs, so round one makes three points ; round two lerps between neighbors to make ; round three lerps those into the single point . That's de Casteljau's algorithm: points, then , , , always with the same . The result is a cubic Bézier curve, the workhorse of graphics. The pen tool in vector drawing apps and the C command in an SVG path draw cubic Béziers, and font outlines are made of cubics or of quadratics (which SVG draws with its Q command), depending on the font format. It works the same way in 3D: lerp , and alike.
const lerp = (a: number, b: number, t: number) => a + t * (b - a);
// One coordinate of a cubic Bézier, by de Casteljau. Call it once for x and once for y.
function bezier(p0: number, p1: number, p2: number, p3: number, t: number): number {
const q0 = lerp(p0, p1, t), q1 = lerp(p1, p2, t), q2 = lerp(p2, p3, t);
const r0 = lerp(q0, q1, t), r1 = lerp(q1, q2, t);
return lerp(r0, r1, t);
}
Reading the control polygon. The dashed path is the control polygon. Three things are always true. The curve starts at and ends at , because at every lerp returns its first point and at its last. It leaves heading toward and arrives at coming from the direction of , so the inner points act as handles that aim the ends (the next lesson makes this exact). And it doesn't pass through or : they pull, but the curve stays short of them.
The convex hull property. A lerp with between and always lands on the segment between its two points, never outside it. So every lies between control points, every between 's, and between 's. Follow that up the chain and the whole curve stays inside the convex hull of the control points: the shape a rubber band makes when you stretch it around them. That's more useful than it sounds. A renderer can skip a curve whose hull is off screen, and a game can test a click or a collision against the hull's simple box before doing any real work.
Splitting a curve for free. De Casteljau gives you more than one point. The points along the left edge of its triangle, , are exactly the control points of the part of the curve from to , and are the control points of the rest. Font renderers use this to draw curves: split in half again and again until each piece is so flat that a straight line is good enough, then draw the lines.
Moving the curve means moving the points. Lerp commutes with moving, rotating and scaling: lerp two points and then rotate the result, or rotate the two points and then lerp, and you land in the same place. So to move, rotate or scale a whole Bézier curve, you only transform its few control points (with the matrices in Computer Graphics). That's why a letter looks the same at any font size: it's the same handful of control points, multiplied by a scale.
A common mistake. It's tempting to think the curve passes through every control point, since they're called points and you placed them on the path you wanted. It doesn't: only the two ends are on the curve, and the middle points are handles that pull it. If you need a curve that goes through a list of points, that's a different tool, Catmull-Rom, later in this unit. A second trap: is not halfway along the curve in distance. It's halfway through the parameter, and the point can cover ground faster on one half than the other. Fixing that is the last lesson of the unit.
Each coordinate of a Bézier curve is a polynomial in , so it's a parametric curve like the ones in Parametric Curves: is the input, and the output is a point.
See it
Worked examples
A quadratic Bézier has control points , and . Find by repeated lerp, then check it with the expanded formula.
- 1
Round one starts on the first leg, from to . The lerp is .
A cubic Bézier has control points , , and . Run de Casteljau's algorithm at to find , and read off the control points of the two halves of the curve.
- 1
At every lerp is a midpoint, so each round is just averaging neighbors.
Practice
Type your answer and check it. Solve them all to complete the lesson.
A quadratic Bézier has control points , and . Find . Enter the point as .
An animator keys a lamp's brightness with a one-dimensional cubic Bézier whose control values are , , and . Use de Casteljau's algorithm to find the brightness at .
A cubic Bézier has control points , , and . Find as exact fractions. Enter the point as .
A type designer draws the arch of a lowercase n as a quadratic Bézier with control points , and in font units. She expected the arch to reach a height of . How high does the curve actually reach, in font units?
A cubic Bézier has control points , , and . Which of these points could lie on the curve?
A game draws a path as the quadratic Bézier with control points , and . The level is then scaled by about the origin and shifted units to the right. Where is the path's point at after the change? Enter the point as .
A quadratic Bézier has control points , and . At what height does the curve cross the vertical line ?
The hardest one here. Get it, and you've got this lesson.
A vector editor splits the cubic Bézier with control points , , and at and keeps the first half. Then it splits that half at its own middle, . Find the point where the second split happens. Enter the point as .
Where it's used
Every letter on your screen is an outline of quadratic or cubic Bézier pieces, scaled to the font size by scaling their control points, and the renderer flattens each piece into short lines by de Casteljau splitting. Vector illustration apps, SVG icons and the motion paths in animation software store the same four-point segments, and the handles you drag are and . Game engines use Bézier rails for cameras, enemies on scripted paths and roller coasters, and test the convex hull first to skip curves that are nowhere near the player.