How does de Casteljau's algorithm evaluate a cubic Bezier curve, and why does the curve not pass through its two inner control points?
answer
- lerps of lerps
- four points, three, two, one
- Bernstein weights sum to one
- handles set the end tangents
basics
~20 sDe Casteljau evaluates a cubic Bezier by repeated lerp: blend each adjacent pair of the four control points by t, then the three results, then the two. The inner points only pull the curve; it touches just the endpoints.
solid answer
~40 sWith control points `P0..P3`, de Casteljau lerps each neighbouring pair by `t` to get three points, lerps those to two, and lerps those to one: six lerps, and the last point is `B(t) = (1-t)^3 P0 + 3(1-t)^2 t P1 + 3(1-t) t^2 P2 + t^3 P3`. At `t = 0` only `P0` has weight and at `t = 1` only `P3`, so the curve interpolates its endpoints; the weight on `P1` peaks at 4/9 and so does `P2`'s, so the inner points act as handles that set the end tangents, `3(P1 - P0)` and `3(P3 - P2)`, and the curve stays inside their convex hull. The two second-level points also give the tangent `3(r1 - r0)` for free, and the intermediate points split the curve into two Bezier halves at `t`.
code
pseudocode · 10 linesfunction bezierPointAndTangent(p0, p1, p2, p3, t):
q0 = lerp(p0, p1, t)
q1 = lerp(p1, p2, t)
q2 = lerp(p2, p3, t)
r0 = lerp(q0, q1, t)
r1 = lerp(q1, q2, t)
point = lerp(r0, r1, t)
tangent = 3 * (r1 - r0)
// split at t: left = (p0, q0, r0, point), right = (point, r1, q2, p3)
return point, tangentgo deeper
Recall that a cubic Bezier has four control points, passes through the first and last, and can be evaluated by repeated lerp.
Walk de Casteljau by hand at t = 0.5, write the Bernstein form, and explain the end tangents and the convex-hull property.
Use the intermediate points for tangents and splitting, compare with the power form on cost and robustness, and set C0, G1 and C1 joints deliberately.
Decide which curve type and handle rules your path tools standardise on, so designers and runtime code agree on what a joint guarantees.
## Control points and what they mean A **cubic Bezier curve** is defined by four **control points** `P0`, `P1`, `P2`, `P3` and a parameter `t` running from 0 to 1. `P0` and `P3` are the endpoints; `P1` and `P2` are **handles** that shape the curve between them. Bezier curves are used for camera paths, motion paths for UI, road and river layouts, and the timing curves inside easing editors, because the handles give an intuitive way to say "leave in this direction, arrive from that one". ## De Casteljau step by step **De Casteljau's algorithm** evaluates the curve with nothing but lerps: 1. lerp each adjacent pair of control points by `t`: `q0 = lerp(P0, P1, t)`, `q1 = lerp(P1, P2, t)`, `q2 = lerp(P2, P3, t)`; 2. lerp the three results the same way: `r0 = lerp(q0, q1, t)`, `r1 = lerp(q1, q2, t)`; 3. lerp the last two: `B(t) = lerp(r0, r1, t)`. That is 3 + 2 + 1 = six lerps for a cubic; a curve with `n` control points takes `n(n - 1) / 2`. A worked example in 2D, with `P0 = (0, 0)`, `P1 = (0, 2)`, `P2 = (4, 2)`, `P3 = (4, 0)` at `t = 0.5`: - level one: `q0 = (0, 1)`, `q1 = (2, 2)`, `q2 = (4, 1)`; - level two: `r0 = (1, 1.5)`, `r1 = (3, 1.5)`; - result: `B(0.5) = (2, 1.5)`. The algorithm is exact, not an approximation. Expanding the nested lerps gives the **Bernstein form** `B(t) = (1-t)^3 P0 + 3(1-t)^2 t P1 + 3(1-t) t^2 P2 + t^3 P3` and substituting the example confirms it: `(1/8)(0, 0) + (3/8)(0, 2) + (3/8)(4, 2) + (1/8)(4, 0) = (2, 1.5)`. ## Why the curve misses the inner points The four Bernstein weights are non-negative for `t` in [0, 1] and always sum to 1, so every point on the curve is a weighted average of the control points. Two consequences follow: - **the curve interpolates only its endpoints.** At `t = 0` only `P0`'s weight is non-zero, and at `t = 1` only `P3`'s. The weight on `P1`, `3(1-t)^2 t`, peaks at 4/9 when `t = 1/3`, and `P2`'s weight peaks at 4/9 when `t = 2/3`, so in general neither inner point is reached; only degenerate layouts, such as all four points on one line, can put an inner point on the curve. In the example the curve rises to a height of 1.5, although both handles sit at height 2; - **the curve stays inside the convex hull** of its control points, which makes the control polygon a cheap conservative bound for culling or coarse overlap tests. The handles instead set the **end tangents**: `B'(0) = 3(P1 - P0)` and `B'(1) = 3(P3 - P2)`. The curve leaves `P0` heading toward `P1` and arrives at `P3` travelling in the direction from `P2` to `P3`, and longer handles make it hold those directions for longer. ## Tangent and splitting for free The intermediate points are not waste: - the tangent at any `t` is `B'(t) = 3(r1 - r0)`; in the example that is `(6, 0)`, horizontal at the top of the arch, as expected from the symmetry; - the curve can be **split** at `t` into two cubic Beziers that together trace the original exactly: `P0, q0, r0, B(t)` and `B(t), r1, q2, P3`. Splitting is what makes **adaptive flattening** work: split recursively until each piece's control polygon is nearly straight, then draw or measure each piece as a line. ## De Casteljau versus the polynomial form Expanding the Bernstein form into powers of `t` gives `B(t) = c0 + c1 t + c2 t^2 + c3 t^3` with `c0 = P0`, `c1 = 3(P1 - P0)`, `c2 = 3(P0 - 2P1 + P2)` and `c3 = P3 - 3P2 + 3P1 - P0`. | Approach | Cost per point, per component | Extra outputs | Numerical behaviour | |---|---|---|---| | de Casteljau | six lerps | tangent and split control points | convex combinations only, robust | | power form with Horner's rule | three multiply-adds, after precomputing four coefficients | none | cheaper; coefficients can lose precision when large terms nearly cancel | When many points are evaluated on one fixed curve, the precomputed power form wins on cost; when you need tangents, splits or robustness, de Casteljau is the natural choice. ## Joining segments into a path Long paths are chains of cubic segments, and the joints are where interviewers probe: - **position continuity (C0)**: the last point of one segment is the first of the next; - **no visible corner (G1)**: the handles either side of the joint are collinear with it, so the tangent direction is continuous; - **matching velocity too (C1)**: the outgoing handle mirrors the incoming one, `P1(next) = 2 * P3(prev) - P2(prev)`, so an object moving with the parameter does not change speed abruptly at the joint. Many curve editors offer exactly these handle modes; knowing what each one guarantees is the part worth explaining.
- How do you join two cubic Bezier segments so a camera passes the joint without a kink?Share the joint point so position is continuous. Keep the handle before the joint, the joint and the handle after it on one line, so the direction is continuous. For equal speed as well, mirror the handle: the next segment's first handle is `2 * P3 - P2` of the previous segment, which makes `3(P1 - P0)` of the next equal `3(P3 - P2)` of the previous.
- Why use de Casteljau at all if the precomputed polynomial form is cheaper per point?De Casteljau gives the tangent and an exact split of the curve at `t` from the same intermediate points, and it uses only convex combinations, so it does not amplify rounding the way large, nearly cancelling power-form coefficients can. Splitting drives adaptive flattening and length measurement. For bulk evaluation of a fixed curve, precomputing the power-form coefficients and using Horner's rule is the cheaper path.
The inner control points behave like magnets beside a flexible rod pinned at both ends: they bend the rod toward themselves, but the pins hold the ends, so the rod never reaches the magnets.
- A cubic Bezier passes through all four of its control points.
- De Casteljau is an approximation that improves with more iterations.
- The curve's starting tangent points from P0 toward P3.
- Two Bezier segments sharing an end point are automatically smooth.
- Moving P1 changes where the curve starts.