B´ezier curves

Michael S. Floater September 10, 2015

These notes provide an introduction to B´ezier curves.

1 Bernstein

Recall that a real of a real variable x ∈ R, with degree ≤ n, is a function of the form

n n i p(x)= a0 + a1x + ··· + anx = aix , ai ∈ R. i=0 X

We will denote by πn the linear (vector) space of all such polynomials. The actual degree of p is the largest i for which ai is non-zero. The functions n 1,x,...,x form a for πn, known as the basis, and the di- mension of the space πn is therefore n + 1. Bernstein polynomials are an alternative basis for πn, and are used to construct B´ezier curves. The i-th of degree n is

n Bn(x)= xi(1 − x)n−i, (1) i i   where 0 ≤ i ≤ n and n n! = . i i!(n − i)!   The first few examples are 0 B0 (x)=1, 1 1 B0 (x)=1 − x, B1 (x)= x,

1 1

0.8

0.6

0.4

0.2

0 0 0.2 0.4 0.6 0.8 1 Figure 1: The cubic Bernstein polynomials

2 2 2 2 2 B0 (x)=(1 − x) , B1 (x)=2x(1 − x), B2 (x)= x , 3 3 3 2 3 2 3 3 B0 (x)=(1−x) , B1 (x)=3x(1−x) , B2 (x)=3x (1−x), B3 (x)= x . The cubic ones are shown in Figure 1. These polynomials are defined for all x ∈ R, but are usually restricted to x ∈ [0, 1] in practice. They have various important properties. They are linearly independent, for if n i n−i cix (1 − x) =0, x ∈ (0, 1), i=0 X then, by dividing by (1 − x)n and letting y = x/(1 − x), we see that

n i ciy =0, y> 0, i=0 X which implies that c0 = c1 = ··· = cn = 0. Since there are n + 1 Bernstein polynomials of degree n, they do indeed form a basis for πn. They are symmetric in the sense that

n n Bi (x)= Bn−i(1 − x). They are positive for x in the open interval (0, 1) and at the endpoints,

n 1 i = 0; n 0 i =0,...,n − 1; Bi (0) = and Bi (1) = (2) (0 i =1,...,n, (1 i = n.

2 They form a partition of unity: by the binomial theorem,

n n n n Bi (x)=(x + (1 − x)) =1 =1. i=0 X They satisfy the recursion formula,

n n−1 n−1 Bi (x)= xBi−1 (x)+(1 − x)Bi (x), (3) which follows from the definition (1) and the binomial identity n n − 1 n − 1 = + . i i − 1 i       In (3) and elsewhere we define

n n B−1 = Bn+1 =0. The computation of the Bernstein polynomials up to degree n can be ar- ranged in the following triangular scheme, with each column being computed from the previous column, starting from the left:

0 1 2 n 1 = B0 B0 B0 ··· B0 1 2 n B1 B1 ··· B1 2 n B2 ··· B2 . . .. . n Bn 2 B´ezier curves

When modelling geometry in some Euclidean space Rd we often model a curve, or part of a curve, as a parametric polynomial,

n i d p(t)= ait , ai ∈ R . (4) i=0 X Since the Bernstein polynomials of degree n form a basis for πn, p can also be represented in the Bernstein form,

n n Rd p(t)= ciBi (u), ci ∈ , (5) i=0 X 3 Figure 2: A cubic B´ezier curve with respect to any interval [a,b], where u is the local variable t − a u = , (6) b − a corresponding to t. If t ∈ [a,b] then u ∈ [0, 1] and vice versa. A polynomial curve expressed in this form is known as a B´ezier curve and the points ci are known as the control points of p. The curve is usually restricted to the parameter domain (parameter interval) [a,b], but is well defined also for t outside [a,b]. The polygon formed by connecting the sequence of control points c0, c1,..., cn is known as the control polygon of p. Figure 2 shows a cubic B´ezier curve with its control polygon. To a large extent the shape of a B´ezier curve relects the shape of its control polygon, which is why it is a popular choice for designing geometry in an interactive graphical environ- ment. As the user moves the control points interactively, the shape of the B´ezier curve tends to change in an intuitive and predictable way. Various properties of B´ezier curves follow from properties of the Bernstein polynomials. For example, from (2), we obtain the endpoint property of B´ezier curves, p(a)= c0, p(b)= cn. Since the Bernstein polynomials sum to one, every point p(t) is an affine combination of the control points c0,..., cn. From this it follows that B´ezier curves are affinely invariant, i.e., if Φ is an affine map in Rd then the mapped curve Φ(p) has control points Φ(ci). So see this, recall that an affine map has the form Φ(x)= Ax + b, x ∈ Rd, for some matrix A of d × d and a vector b of length d. Since the

4 Bernstein polynomials sum to one, n n n n n n Φ(p(t)) = AciBi (u)+ b = (Aci + b)Bi (u)= Φ(ci)Bi (u). i=0 i=0 i=0 X X X Since the Bernstein polynomials are non-negative in [0, 1], the point p(t), with t ∈ [a,b], is a convex combination of the control points c0,..., cn, and so p, restricted to [a,b], lies in the convex hull of its control points:

n

C := { λici : λ0,...,λn ≥ 0, λi =1}. i=0 i X X By treating each of the d coordinates of p separately, a similar reasoning shows that p restricted to [a,b] also lies in the bounding box

[α1, β1] × [α2, β2] ×···× [αd, βd], where, if the point ci has coordinates ci1,...,cid,

αk = min cik and βk = max cik, k =1,...,d. 0≤i≤n 0≤i≤n Bounding boxes are used in various algorithms, and are easier to compute than convex hulls.

3 The de Casteljau algorithm

One way of computing a point p(t) of the B´ezier curve p is first to evaluate n the Bernstein polynomials Bi at u and then use the formula (5). Another, 0 more direct method is de Casteljau’s algorithm. We first set ci = ci, and then for each r =1,...,n, let

r r−1 r−1 ci = (1 − u)ci + uci+1 , i =0, 1,...,n − r. (7) The last point computed in this algorithm is the point on the curve:

n p(t)= c0 . We can show this by showing more generally that for any r =0, 1,...,n,

n−r r n−r p(t)= ci Bi (u). (8) i=0 X 5 Figure 3: de Casteljau algorithm, u =0.3

This equation clearly holds for r = 0, and we can use induction on r for the general case. Suppose (8) holds for some r ≤ n − 1. Then applying the recursion formula (3) to the right hand side gives

n−r r n−r−1 n−r−1 p(t)= ci uBi−1 (u)+(1 − u)Bi (u) i=0 nX−r−1  r r n−r−1 = uci+1 + (1 − u)ci Bi (u). i=0 X  This shows that (8) also holds with r replaced by r + 1, and therefore, by induction, for all r =0, 1,...,n. Like the recursive algorithm for computing Bernstein polynomials, the de Casteljau algorithm can be viewed as a trian- gular scheme, here arranged row-wise, with each row being computed from the row above: 0 0 0 0 c0 c1 c2 ··· cn 1 1 1 c0 c1 ··· cn−1 ...... n−1 n−1 c0 c1 n c0 Figure 3 illustrates the algorithm applied to the B´ezier curve of Figure 2 with u =0.3. A numerical example with n =3 is a = 0, b = 1, t = u =2/3, d = 1 and

[c0 c1 c2 c3]=[4 0 4 18]. The three steps of the algorithm are then: [4 0 4 18] → [4/3 8/3 40/3] → [20/9 88/9] → [196/27].

6 r The point ci of the de Casteljau algorithm is itself the result of applying r steps of the algorithm to the subsequence of control points ci, ci+1,... ci+r, r and so ci , viewed as a function of t, is itself a B´ezier curve of degree r:

r r r r ci = ci (t)= ci+jBj (u). (9) j=0 X 4 Derivatives

To find the first derivative of p in (5), we apply the chain rule to make the conversion d 1 d = , dt L du where L = b − a. We also use a formula for the derivative of a Bernstein polynomial. Differ- entiating (1) with respect to x and using the product rule gives

d Bn(x)= n Bn−1(x) − Bn−1(x) . (10) dx i i−1 i  From these observations we find that the derivative of the B´ezier curve in (5) with respect to its parameter t is

n− n− n 1 1 p′(t)= c Bn−1(u) − c Bn−1(u) . (11) L i+1 i i i i=0 i=0 ! X X Thus one way of expressing the derivative is as

n− n 1 p′(t)= ∆c Bn−1(u), (12) L i i i=0 X where ∆ denotes the forward difference operator,

∆ci = ci+1 − ci.

This means that the derivative of p is itself a B´ezier curve with respect to [a,b] with control points, which we now view as vectors, n∆ci/L. For each

7 ′ t ∈ [a,b], the tangent vector p (t) lies in the convex cone of the vectors ∆ci, i.e., in n−1

C := { λi∆ci : λ0,...,λn−1 ≥ 0}. i=0 X and by the endpoint property of B´ezier curves,

′ n ′ n p (a)= ∆c and p (b)= ∆c − . L 0 L n 1 An alternative way of expressing the derivative is in terms of the inter- mediate points (9) of the de Casteljau algorithm. Setting r = n − 1 in (9), it follows from (11) that n n p′(t)= cn−1(t) − cn−1(t) = ∆cn−1(t). (13) L 1 0 L 0  5 Higher derivatives

Applying the derivative formula (12) repeatedly leads to

n−r dr n! p(r)(t)= p(t)= ∆rc Bn−r(u), dtr (n − r)!Lr i i i=0 X for any r =1,...,n, where ∆r is the r-th forward difference operator

r r−1 r−1 ∆ ci =∆ ci+1 − ∆ ci.

At the endpoints of the curve, the r-th derivative depends only on the first or last r + 1 control points:

(r) n! r (r) n! r p (0) = ∆ c and p (1) = ∆ c − . (n − r)!Lr 0 (n − r)!Lr n r

Alternatively, in terms of the intermediate de Casteljau points, differentiating (13) repeatedly gives

n! p(r)(t)= ∆rcn−r(t). (n − r)!Lr 0

8 6 Integration

Integrating the derivative formula (10) over x ∈ [0, 1] gives

1 1 n n n−1 n−1 Bi (1) − Bi (0) = n Bi−1 (x) dx − Bi (x) dx , Z0 Z0  and since the left hand side is zero for i =1,...,n − 1, we deduce that

1 1 n−1 n−1 Bi−1 (x) dx = Bi (x) dx. Z0 Z0 Thus the integral over [0, 1] of each Bernstein polynomial of the same degree is constant. Since the Bernstein polynomials of degree n sum to one and there are n +1 of them,

1 1 Bn(x) dx = . i n +1 Z0 It follows that the integral of p in (5), normalized by the difference L = b−a, is 1 b c + c + ··· + c p(t) dt = 0 1 n , L n +1 Za which is the barycentre of the control points c0,..., cn.

7 Conversion to B´ezier form

Sometimes we need to convert a polynomial from monomial form to B´ezier form and vice versa. For simplicity we will treat only the canonical case that a = 0 and b = 1 in (5), in which case u = t. Suppose we start with the monomial form (4) and want to convert it to the B´ezier form (5). We use the fact that

n−i n − i 1=(1 − t + t)n−i = tj(1 − t)n−i−j, j j=0 X  

9 to show that

n n−i n − i p(t)= a ti+j(1 − t)n−i−j i j i=0 j=0   Xn Xn n − i = a tj(1 − t)n−j, i j − i i=0 j=i X X   n j n − i = a tj(1 − t)n−j, i j − i j=0 i=0 X X   and therefore j 1 n − i c = a . j n j − i i j i=0 X   Conversely, suppose we want to convert the B´ezier form (5) to the mono- mial form (4). To do this, observe that

n−i n − i (1 − t)n−i = (−1)jtj, j j=0 X   and so

n n−i n n − i p(t)= c (−1)jti+j i i j i=0   j=0   Xn Xn n n − i = c (−1)j−itj, i i j − i i=0 j=i X   X   n j n n − i = c (−1)j−itj, i i j − i j=0 i=0 X X    and it follows that

j n n − i a = (−1)j−ic . j i j − i i i=0 X   

10 This can be alternatively written as

j n j n a = (−1)j−ic = ∆jc . j j i i j 0 i=0 X     

11