Example Problem #3 (Bezier curve)
As a last example, we will show how to relate a cubic Bezier representation to a parametric cubic spline formulated using the methodology shown here. A cubic Bezier curve is represented by 4 control points, 1 each to define the beginning and end of the curve, and 2 additional control points, not necessarily on the curve, to define the boundary conditions at either end. A common representation of a cubic Bezier (http://en.wikipedia.org/wiki/B%C3%A9zier_curve) is:
B(t) = (1-t)3P0 + 3t(1-t)2P1 + 3t2(1-t)P2 + t3P3..........(0 ≤ t ≤ 1)
which is just a compact form of representing 2 equations:
x(t) = (1-t)3x0 + 3t(1-t)2x1 + 3t2(1-t)x2 + t3x3..........(0 ≤ t ≤ 1)
y(t) = (1-t)3y0 + 3t(1-t)2y1 + 3t2(1-t)y2 + t3y3..........(0 ≤ t ≤ 1)
P0 = (x0,y0) and P3 = (x3,y3) are control points defining the endpoints of the Bezier curve and P1 = (x1,y1) , P2 = (x2,y2) are additional control points the define the shape of the curve. With the above equations it is easy to verify that x = x0, y = y0 at t = 0 and x = x3, y = y3 at t = 1. By expanding the above equations and collecting terms, it can be shown that a cubic Bezier curve can be also represented in traditional polynomial form:
x(t) = axt3 + bxt2 + cxt + dx..........(0 ≤ t ≤ 1)
y(t) = ayt3 + byt2 + cyt + dy..........(0 ≤ t ≤ 1)
where the coefficients of the polynomials are related to the Bezier control points by the following matrix equation (Note: . means zero):
Code:
┌ ┐ ┌ ┐ ┌ ┐
│ax ay │ │-1 3 -3 1│ │x0 y0│
│bx by │ = │ 3 -6 3 .│ │x1 y1│
│cx cy │ │-3 3 . .│ │x2 y2│
│dx dy │ │ 1 . . .│ │x3 y3│
└ ┘ └ ┘ └ ┘
This is essentially a transformation matrix that allows conversion between 2 different representations of a parametric cubic polynomial. Lets find the Bezier control points for example problem #1. Before proceeding, however, there is a subtle but important point that needs to be discussed. The above relations are valid for 0 ≤ t ≤ 1. In terms of the cubic spline formulation shown here, by comparing equations it is clear that t corresponds to the quantity (s-s0). Thus, in order to convert a parametric cubic polynomial to traditional Bezier form, the formulation must be done in such a way that (s-s0) varies from 0 to 1 in each segment. Actually, this is easy. All that is needed is to increment s by 1 for each point and not scale the result. Thus, s = [0, 1, 2, 3]. This method of choosing s has the additional benefit of h1 = h2 = h3 = h = 1, which allows the use of the simplified version of the cubic spline equation. Choosing values for free end boundary conditions (for a pleasing result), we get:
Code:
┌ ┐ ┌ ┐ ┌ ┐ ┌ ┐
│1 . . . │ │x1" y1"│ │ 1 0.6│ │ 6 3.6│
│1 4 1 . │ │x2" y2"│ = 6 │x3-2x2+x1 y3-2y2+y1│ │ 18 6│
│. 1 4 1 │ │x3" y3"│ │x4-2x3+x2 y4-xy3+y2│ = │ -6 -18│
│. . . 1 │ │x4" y4"│ │ -0.6 -1│ │-3.6 -6│
└ ┘ └ ┘ └ ┘ └ ┘
The solution is x" = [6, 3.36, -1.44, -3.6]T and y" = [3.6, 1.44, -3.36, -6]T. From the cubic spline tutorial, we can conveniently represent the equations to determine the spline segment coefficients by the following matrix equation (example shown for 1st segment).
Code:
┌ ┐ ┌ ┐ ┌ ┐
│ax ay │ │ . . -1/6 1/6│ │x1 y1 │
│bx by │ = │ . . 1/2 .│ │x2 y2 │
│cx cy │ │-1 1 -1/3 -1/6│ │x1" y1"│
│dx dy │ │ 1 . . .│ │x2" y2"│
└ ┘ └ ┘ └ ┘
Since all xi, yi, xi", yi" are known, the spline coefficients can be readily calculated. Once the spline coefficients are determined, the associated Bezier control points can be calculated using the relation previously shown.
The polynomial coefficients are thus:
Code:
┌ ┐ ┌ ┐ ┌ ┐
│ax1 ay1 ax2 ay2 ax3 ay3 │ │ . . -1/6 1/6│ │x1 y1 x2 y2 x3 y3 │
│bx1 by1 bx2 by2 bx3 by3 │ = │ . . 1/2 .│ │x2 y2 x3 y3 x4 y4 │
│cx1 cy1 cx2 cy2 cx3 cy3 │ │-1 1 -1/3 -1/6│ │x1" y1" x2" y2" x3" y3"│
│dx1 dy1 dx2 dy2 dx3 dy3 │ │ 1 . . .│ │x2" y2" x3" y3" x4" y4"│
└ ┘ └ ┘ └ ┘
┌ ┐ ┌ ┐
│ . . -1/6 1/6 │ │ 1 0 -1 0 0 1│
= │ . . 1/2 . │ │ -1 0 0 1 0 -1│
│-1 1 -1/3 -1/6 │ │ 6 3.6 3.36 1.44 -1.44 -3.36│
│ 1 . . . │ │3.36 1.44 -1.44 -3.36 -3.6 -6│
└ ┘ └ ┘
┌ ┐
│-0.44 -0.36 -0.8 -0.8 -0.36 -0.44│
= │ 3 1.8 1.68 0.72 -0.72 -1.68│ = polynomial coefficients
│-4.56 -1.44 0.12 1.08 1.08 0.12│
│ 1 0 -1 0 0 1│
└ ┘
And the Bezier control points are (note the matrix inverse):
Code:
┌ ┐ ┌ ┐-1 ┌ ┐
│x01 y01 x02 y02 x03 y03 │ │-1 3 -3 1│ │ax1 ay1 ax2 ay2 ax3 ay3│
│x11 y11 x12 y12 x13 y13 │ = │ 3 -6 3 .│ │bx1 by1 bx2 by2 bx3 by3│
│x21 y21 x22 y22 x23 y23 │ │-3 3 . .│ │cx1 cy1 cx2 cy2 cx3 cy3│
│x31 y31 x32 y32 x33 y33 │ │ 1 . . .│ │dx1 dy1 dx2 dy2 dx3 dy3│
└ ┘ └ ┘ └ ┘
┌ ┐ ┌ ┐
│. . . 1 │ │-0.44 -0.36 -0.8 -0.8 -0.36 -0.44│
= │. . 1/3 1 │ │ 3 1.8 1.68 0.72 -0.72 -1.68│
│. 1/3 2/3 1 │ │-4.56 -1.44 0.12 1.08 1.08 0.12│
│1 1 1 1 │ │ 1 0 -1 0 0 1│
└ ┘ └ ┘
┌ ┐
│ 1 0 -1 0 0 1│
= │-0.52 -0.48 -0.96 0.36 0.36 1.04│= Bezier control points
│-1.04 -0.36 -0.36 0.96 0.48 0.52│
│ -1 0 0 1 0 -1│
└ ┘
Conclusion:
We have extended our knowledge of cubic splines to include the powerful and flexible parametric version and have fit various shapes (including a closed loop) to a set of given points. We have also shown how to determine the cubic Bezier control points of a curve.

.