This page is intended to be a brief reference on implementing Bézier curves. It is not intended to be a full discussion of the topic, only a reference.

1 Definition

A Bézier curve is a sequence of control points on a parameter interval.

The control points may be scalars or vectors, and there may be an number of them; we will denote the control points as p0,p1,,pnp_0, p_1, \dots, p_n. The nn here is the order of the Bézier curve and is one less than the number of control points.

We will refer to the parameter interval as going from t0t_0 to tnt_n. We assume t0<tnt_0 < t_n.

2 de Casteljau’s Algorithm

To find the point on a Bézier curve at some parameter value tt', we proceed as follows.

Let tt be the relative parameter value defined by t=tt0tnt0t = \frac{t'-t_0}{t_n-t_0}.

If n=0n=0, return p0p_0. Otherwise, define a set of control points where the new nn is the old n1n-1 and the new pip_i is the old (1t)pi+(t)pi+1(1-t) p_i + (t) p_{i+1}; repeat until the new nn is zero. The operation (1t)pi+(t)pi+1(1-t) p_i + (t) p_{i+1} is called a lerp (short for linear interpolation).

JavaScript code for basic de Casteljau
const lerp = (t,p0,p1) => add(mul(p0,1-t), mul(p1,t))
const lbez = (t, ...p) => {
  while(p.length > 1) p = p.slice(1).map((e,i) => lerp(t,p[i],e))
  return p[0]
}

In addition to providing the point on the curve at tt, De Casteljau’s algorithm also splits the original Bézier curve into two: the set of all p0p_0 (in the order created) define the portion of the Bézier curve in the interval [t0,t][t_0, t] and the set of all pnp_n (in the reverse order created) define the portion of the Bézier curve in the interval [t,tn][t, t_n]

JavaScript code for de Casteljau curve spliting
const bezcut = (t, ...p) => {
  let front = [], back = []
  while(p.length > 0) {
    front.push(p[0])
    back.unshift(p[p.length-1])
    p = p.slice(1).map((e,i) => lerp(t,p[i],e))
  }
  return [front, back]
}

3 Comments

At t=t0t = t_0, the value of a Bézier curve is p0p_0. At t=tnt = t_n, the value of a Bézier curve is pnp_n. In general, the Bézier curve does not pass through any of its other control points.

Bézier curves always remain inside the convex hull of their control points.

Within the interval t0ttnt_0 \le t \le t_n, de Casteljau’s algorithm is unconditionally numerically stable: it gives the value of the polynomial with as much numerical precision as the control points and tt values are themselves specified. Outside that interval de Casteljau’s algorithm still works in principle, but it is not stable, accumulating numerical error at a rate polynomial in the distance outside the interval.

Bézier curves also can be degree-elevated and degree-reduced; can efficiently determine their derivative using a hodograph; can represent conic sections if the control points are homogeneous coordinates; and can be generated in a smooth spline using B-splines and their variants. For an extensive treatment, see Thomas Sederberg’s book Computer Aided Geometric Design.