You are on page 1of 13

An Introduction to Bezier Curves, B-Splines, and Tensor Product Surfaces with History and Applications

Benjamin T. Bertka University of California Santa Cruz May 30th , 2008

History

Before computer graphics ever existed there were engineers designing aircraft wings and automobile chassis by using splines. A spline is a long exible piece of wood or plastic with a rectangular cross section held in place at various positions by heavy lead weights with a protrusion called ducks, where the duck holds the spline in a xed position against the drawing board [2]. The spline then conforms to a natural shape between the ducks. By moving the ducks around, the designer can change the shape of the spline. The drawbacks are obvious, recording duck positions and maintaining the drafting equipment necessary for many complex parts will take up square footage in a storage facility, costs that would be absorbed by a consumer. A not so obvious drawback is that when analyzed mathematically, there is no closed form solution [3]. However, in the 1960s a mathematician and engineer named Pierre Bezier changed everything with his newly developed CAGD tool called UNISURF. This new software allowed designers to draw smooth looking curves on a computer screen, and used less physical storage space for design materials. Beziers contribution to computer graphics has paved the road for CAD software like Maya, Blender, and 3D Max. His developments serve as an entry gate into learning about modern computer graphics, which spawned a relatively new mathematical object known as a spline, or a smooth curve specied in terms of a few points. 1

Applications for Bezier curves and B-splines

To see why splines are important, lets consider the problem of designing an aircraft wing. Lets assume that the Air Force is designing the latest and greatest jet ghter plane, and the wing is currently being designed according to specications that include and promote optimal behavior under extreme turbulence due to mach speeds. To even complicate the design further, the wing has to look nice on the rest of the jet so as to promote more military funding and generate recruits into the Air Force. There are many dierent possible designs for a wing, some that are more optimal than others, and some that are more aesthetically pleasing that others as well. To nd a balance between optimizing the air ow around the wing and how the shape looks is quite a task. Assume for a moment that your job as a visualization specialist is to make use of the computer system that utilizes recorded data from an aircraft testing facility. Their system is able to relate the ow of turbulence around the wing of an aircraft to the shape of the aircrafts wing. You are asked to create a piece of software using their model to allow an ecient way for a designer to specify an optimal and aesthetically pleasing shape for the wing. The relation between shape and turbulence is already completed, so it is your job to give global control to the designer. Mainly, a way of specifying smooth curves on a computer screen is required, and splines are the natural way of completing the task. In order to eectively represent a smooth curve on a computer screen, we need to somehow approximate it. We come to this realization upon the simple fact that a computer can only draw pixels, which have a predened width and height. If you get really close to an LCD screen and observe the tiny squares making up the outline of an image, its easy to understand that everything represented in computer graphics is an approximation at best.

Bezier Curves

We start by letting the four points of a control polygon be the set P, where P = { P0 , P1 , P2 , P3 }. The position of these points in two or three dimensions determines the curvature of the curve. Now let Q(u) be a parametrically dened vector valued function where 0 u 1. As u varies from 0 to 1, the vector values of Q(u) sweep out the curve [3]. Recall the Bernstein polynomials of degree n (we will use this in the general case of degee-n Bezier curves):
n Bi (u) =

n i u (1 u)ni i

(1)

, where i = 0, 1, 2, ... , n, and n i = n! i!(n i)! (2)

Bezier curves use the special case of the Bernstein polynomial where n = 3. Since Bezier curves use the Bernstein polynomial as a basis, it is ok to use the term Bezier/Bernstein spline when talking about these curves. Now we can mathematically dene a degree three Bezier curve. Let Q(u) be such a curve: 2

3 3 3 3 Q3 (u) = B0 (u)P0 + B1 (u)P1 + B2 (u)P2 + B3 (u)P3 3. 3 , where each Bi (u) term is scaler valued in In matrix form we can also write:

(3)

, and the control point Pi is vector valued in (4)

Q3 (u) = [B][P ]

Since we are using the Bernstein basis, several properties of Bezier curves are revealed: each basis function is real; the degree of the polynomial dening the curve segment is one less than than the number of points that compose the control polygon; the rst and last points on the curve are coincident with the rst and last points of the control polygon; the tangent vectors at the ends of the curve have the same direction as the rst and last spans of the control polygon. Finding expressions for each basis term is straightforward for the degree three case, but can be very tedious for splines of degree greater than three. Knowing that n = 3 and we have 4 control points, by using (1) we compute:
3 B0 (u) = (1 u)3 3 B1 (u) = 3u(1 u)2 3 B2 (u) = 3u2 (1 u) 3 B3 (u) = u3

(5) (6) (7) (8)

Putting these terms back into (3) gives us our polynomial Q(u): Q3 (u) = (1 u)3 P0 + 3u(1 u)2 P1 + u2 (1 u)P2 + u3 P3 (9)

Hence, for each value of u, we nd point on the Bezier curve. A computer graphics library like OpenGl can take each point ad connect them with lines, making it easy to create a program that allows for a designer to specify a control polygon with four clicks of a mouse. The program can easily allow for repositioning of the points via drag and drop, thus giving a designer an easy way to specify a smooth form (see Figure 1).

Figure 1: A Bezier curve of degree three. This curve was made using an interactive program written by the author.

Like with many polynomials, the Bezier curve has sweet spots along the trajectory that gives a maximum amount of pull. We usually dont pull on the start and end points of a curve, so lets just consider the degree three case for simplicitys sake. A maximum value exists 3 3 for the basis functions B1 (u1 ), and B2 (u2 ). To nd the maximum value for ui , we recall the mean value theorem: If f is a function that is continuous and dierentiable on a closed interval [a,b], then there exists a number c inside the interval (a,b) such that: f (b) f (a) = f (c)(b a) (10)

3 Let Bi (u) be a Bernstein basis function that is continuous on the closed interval [0,1]. Then 3 the second and third control points corresponds to i=1,2, and by (6), B1 (u) = 3u(1 u)2 , and 3 by (7), B2 (u) = 3u2 (1 u).

Since each basis function is continuous, they are dierentiable, and we let B 3 (u) denote the i derivative of the ith basis function of Q(u). Set this derivative to zero, and then (10) implies:
3 3 B1 (1) B1 (0) = B 1 (c1 ) = 0 3 3 B2 (1) B2 (0) = B 2 (c2 ) = 0 3 3

(11) (12)

Using (1), We know for sure that (11) and (12) are true, since for an arbitrary ith term of Q(u):
3 3 Bi (1) Bi (0) = 0

(13)
3 i (u2 ).

Hence, we can nd a u1 , u2 [0,1] such that B =B four derivatives of Q(u)s basis functions (5)-(8) be computed as: B 0 (u) = 3u2 + 6u 3 B 1 (u) = 9u2 12u + 3 B 2 (u) = 9u2 + 6u B 3 (u) = 3u2
3 3 3 3

3 i (u1 )

We start by letting the

(14) (15) (16) (17)

Setting (15) to zero we nd u1 = 1/3, and evaluating (6) at u1 , we nd that the maximum value of the second basis function of Q(u) to be 4/9. Similarly, we set (16) to zero and nd that u2 = 2/3, and evaluating (7) at u2 , we nd that the value of the third basis function of Q(u) to be 4/9. Hence, P1 and P2 have the most inuence or pull, at u1 = 1/3, and u2 = 2/3, respectively; where the max value for both P1 and P2 is 4/9. It is no coincidence that the max value for the second and third basis functions are both 4/9. It can be shown, although not included here, that (5) and (6) are the same when evaluated at u=1/3, and (7) and (8) are the same when evaluated at u = 2/3. This is due to the symmetry of the Bernstein basis. Below are some examples of more Bezier curves:

Figure 2: A Bezier curve of degree ve.

Figure 3: A Bezier curve of degree nine.

In general, a Bezier spline of degree k is dened on n = k + 1 control points, where the set of control points P = { P0 , P1 , . . ., Pk } forms a control polygon with n vertices. Let Q(u) be a parametrically dened degree k Bezier spline, then:
k

Qk (u) =
i=0

k Bi (u)Pi

(18)

k , where the basis Bi (u) is dened using (1), the Bernstein polynomial, and u [0,1].

In this general case there are some immediate consequences of using the Bernstein basis:
k Bi (u) k k B0 (0) = Bk (1) = 1 k k Bi (u) = 1 i=0 k Bi (u) 0

(19) (20) (21) (22)

By (20), the curve starts at Q(0) = P0 , and ends at Q(1) = Pk . By (21) and (22), it is implied that each point on Q(u) is a weighted average of control points. Taken together, these features force a Bezier curve to lie entirely in the convex hull of the control polygon. A Bezier curve of degree k lies tangent to the rst and last control points. To see how this is true, we rst formalize our denition of the Bezier derivative. Let Q(u) be a Bezier curve of degree k with the set of k + 1 control points, P. Then its derivative Q(u) is dened as:
k1

Q k (u) = k
i=0

k1 Bi (u)(Pi+1 Pi )

(23)

We see that the degree is decreased by one and Q(u) is also a Bezier curve with control points k(Pi+1 - Pi ) Evaluating Q(u) at 0 and 1: Q k (0) = k(P1 P0 ) Q k (1) = k(Pk Pk1 ) (24) (25)

By (23), (24), and (25), we prove that the Bezier curve of degree k starts in the direction of P1 P0 , and ends in the direction of Pk Pk1 .

Rational Bezier Curves

Now that we understand Bezier curves of degree k, we can consider the rational form of a Bezier curve. Graphics Processing Units, or GPUs actually need more information than just a point {x, y, z} 3 . The problem with just a regular point is that there is no info on how to project it. Homogeneous coordinates exist in order to make the projective transformation easier to work with [5]. The rational form has advantages in that it can represent a wide range of curves, and surfaces (more on surfaces in a little while). Curves could be in the form of circles, ellipses, parabolas, and hyperbolas; surfaces can be in the form of spheres, ellipsiods, cylinders, cones, paraboloids, hyperboloids, and hyperbolic paraboloids [1]. The only dierence in Rational Bezier curves is that the coordinates that specify the curve are in one dimension higher than their nonrational counterpart. For example, if we wish to express a Bezier curve in 3 , we specify a control point as {x, y, z, }, where is a weight that allows for the transition between regular and homogeneous coordinate space. Let h be a map from homogenous coordinate space to regular space, then we dene h as h(x, y, x, w) = (x/w, y/w, z/w) (26)

In computer graphics homogeneous coordinates allow the designer to work with normalized points for = 1, and also to dene a point at innity, saw when = 0 [4]. Now we make a denition of a rational Bezier curves: Let i for i=0,. . ., k, be the k + 1 weights corresponding to the control points Pi . The the rational Bezier curve of degree k becomes: Qk (u) =
k k i=0 wi Bi (u)Pi k k r=0 wr Br (u)

(27)

With some rearranging we can write (27) as linear combination of rational basis functions:
k

Qk (u) =
i=0

Pi

k wi Bi (u) k k r=0 wr Br (u)

(28)

k Where we denote the term in brackets by Ri (u), k Ri (u) = k wi Bi (u) k k r=0 wr Br (u)

(29)

And we now have a familiar looking form by replacing the terms in brackets in (28) by the k new term Ri (u) as dened in (29),
k

Qk (u) =
i=0

k Ri (u)Pi

(30)

Hence we have the same curve equation as (18), but the univariate basis is rational. It is immediately implied that all the rules for the nonrational Bezier curve carry over to the rational Bezier curve [1]. Noting that if the denominator if the rational bezier curve is one, the nonrational and rational curves are the same (except for the extra in the coordinates).

Rational B-Splines

B-splines are like Bezier curves because they both use a control polygon to dene the curve, and are helpful due to their control points local control of the resulting shape. The B in B-spline stands for basis, and the basis is specied by the Cox-de Boor formula for computing the basis function. What uniquely sets them apart from Bezier curves is that a vector of scalars called a knot vector is gured in to the computation of the basis functions. When these knots are spaced evenly, the B-spline is said to be uniform, and non-uniform otherwise. The basis function considers the knot vector in every computation. In general, a B-spline can be rational or non-rational, depending on the use of homogeneous coordinates. Let Ck,n (u) denote a uniform rational B-spline of order k (degree k 1), where k n. Let i for i = 1, ...,n be the n weights corresponding to homogeneous control points {P1 , P2 . . . Pn }. Let x be a knot vector such that x1 x2 . . . xn+k , then the rational B-spline becomes: Ck,n (u) =
n k i=1 i Ni (u)Pi n k r=1 r Nr (u)

(31)

where the basis functions N are dened using the Cox-de Boor algorithm [6]:
1 Set Nj (u) = 1 if xj u < xj+1 , and zero otherwise. p+1 k Let the order k = p + 1, then Nj (u) becomes Nj (u), where p+1 Nj (u) =

We may regroup the terms in (31) as we did in the previous sections as


n

u xj xj+p+1 u p Nj (u) + N p (u) xj+p xj xj+p+1 xj+1 j+1 i Nik (u) n k r=1 r Ni (u)

(32)

Ck,n (u) =
i=1

Pi

(33)

where we denote the term in brackets by Uik (u), where Uik (u) = i Nik (u) n k r=1 r Ni (u)
n

(34)

And substituting (34) back into our equation (33), we get the compact expression for Ck,n (u), Ck,n (u) =
i=1

Uik (u)Pi

(35)

Hence the B-spline is dened by its basis, where the basis is heavily inuenced by the knot vector. If the knots were not evenly spaced apart, the curve would be a non-uniform rational B - spline, a.k.a. NURB. Computing a B-spline is a formidable task. And we explain below the computation in detail to have a good understanding of it.

5.1

B-spline Computation

Normally, the B-spline is computed by a computer, since a smooth curve needs small time steps. To make comprehension easier for the novice in computer graphics, or non-programmer, my best attempt at describing how the computation is in terms of a regular uniform B-spline. We start by choosing an order for the spline. In our case, let the order be k. We specify a set of n control points. We call this set the control set. Depending on desired smoothness, the number of points on our curve can vary, and denote this set of points to be the curve set. With this information we may now begin computing. The rst thing we need to do is specify a uniform knot vector x of length n+k. We compute it as follows. Set each knot xi to be zero. Then for each 1 < i n + k, check to see if both conditions, i > n and i < n + 2 hold. If they do, set xi to the value of xi1 +1. If the conditions do not hold, just set xi to the value of xi1 . As an example, If we choose k = n = 4, we nd that our knot vector x = {0, 0, 0, 0, 1, 1, 1, 1}, which also happens to be the correct knot vector to make a Bezier curve out of a B spline. Before we can calculate the points in the curve set, we need to decide on an appropriate step value for the parameter u. The proper step is found by dividing the value of knot xn+k by one less than the number of points on the curve set (19 steps plus the zeroth step is 20 steps) . Using the knot vector from the previous example, if we had 20 points in our curve set, and n + k = 8, then the step would be 1/19 which is about 0.052632. We now begin the task of computing the curve set points on the B-spline. We need to keep in mind that the number of basis functions we compute for each time step is going to equal that of the number of points in the control set. So for the entire spline, the number of basis computations is going to be equal to the product of the magnitudes of the control and curve sets. So in our running example, we have 20 points on the curve set to compute and four control points, so there is 80 basis functions to compute! At each step, use the Cox-de Boor algorithm to compute the value of the basis function. During each iteration of the steps, the entire knot vector x is considered in with the step value u. We see that the Cox-de Boor algorithm is recursive, so when using this system special care has to made in order to compute the basis correctly. Once we have a set of n basis functions for the control points at a specic step u, we nd the coordinates for the curve point at the step by multiplying the ith basis function to the ith control point. The resulting values are inserted into the curve set, and we generate a collection of points that when plotted together, and connected with line segments can aesthetically resemble a curve. The number of computations required to make a B-spline are really large, so it is obvious that a computer is needed for the computation of splines. As a concrete example, let a set of four control points be as follows: P4 = {(1, 1, 1), (2, 3, 1), (3, 3, 1), (5, 1, 1)}. Letting n = 4, k =4, knot vector x = {0, 0, 0, 0, 1, 1, 1, 1}, we use a computer program for computing the following basis functions for 20 points on the control set using the previously mentioned step (see screen shot from my computer).

Figure 4: Computing 20 points on a B-spline for n=4, k=4, x = {0, 0, 0, 0, 1, 1, 1, 1}

10

Tensor Product Surfaces

Now that we have discussed rational Bezier curves and B-Splines, it is time to introduce tensor product surfaces. For both the rational and non rational case, properties of their cohabitant curves apply. A tensor product surface is dened by a control net, similar to that of a control polygon for a curve, only we parameterize in two dierent directions, namely u [0,1] and v [0,1]. This control net is specied by a set of points, where if we use homogeneous coordinates the surface is referred to a rational tensor product surface. For simplicities sake, we use the rational form of the tensor product surface with a Bernstein basis for our denition. Let us dene a rational tensor product surface Qk,l (u, v) as being a degree k in the u direction and degree l in the v direction. Then our rational tensor product surface becomes Qk,l (u, v) =
k l l k i=0 j=0 ij Pij Bi (u)Bj (v) k l k l r=0 s=0 rs Br (u)Bs (v)

(36)

where each control point in the set P of three dimensional points that make up the control net will be denoted in homogeneous coordinates as Pi,j = {ij xij , ij yij , ij zij }. And the basis k nction Bi (u) is the Bernstein polynomial from (1). Just like we rearranged the rational curve in (28), we rearrange the rational surface to be
k l

Qk,l (u, v) =
i=0 j=0

Pij

k l ij Bi (u)Bj (v) k r=0 l k l s=0 rs Br (u)Bs (v)

(37)

kl where the term inside the brackets is denoted by Rij (u, v) kl Rij (u, v)

k l ij Bi (u)Bj (v) k r=0 l k l s=0 rs Br (u)Bs (v)

(38)

Thankfully we are able to make the replacement of expression (34) within (31), and Qk,l (u, v) kl is rewritten in a way that highlights the bivariate basis function Rij (u, v)
k l kl Pij Rij (u, v) i=0 j=0

Qk,l (u, v) =

(39)

Hence, rational Bezier curves and tensor product surfaces provide an intuitive way of approximating a designers models based on control polygons, and control nets. By merely changing the weights, we can make a Bezier curve become a rational curve, and a rational tensor product surface a Bezier surface. A potential problem with Bezier curves and surfaces is that their control points have global control. While computing is ecient, just moving one control point has a radical eect on the shapes image. This can be bad when only minor adjustments may be needed when trying to create a certain shape. If we choose local control, we would want a B-spline surface. A B-spline tensor equation is going to look very similar to the Bezier tensor equations so it is omitted. However, if we wished to translate a Rational Bezier surface into a Rational B-spline surface, we would have similar parameterization in u-v space, use uniform knot vectors, and homogenous coordinates, hence creating an URB. If the knots are not evenly spaced, we would have a NURB, an industry standard for use in surface representation.

11

Sample Data Structure

The images in this paper were generated by a computer program written by the author. This program was written in C++ and uses OpenGL libraries, and specically glMap1() and glEvaluate() helper commands to create the curve (see OpenGL documentation for more detailed explanation). The data structure to handle the Bezier object is in the form of a display list, and illustrates the ease at which a curve is generated. While the interactive program is too long to include in this paper, the vital part of the generation of the curve is shown here.

Figure 5: A Bezier object in the form of a display list. Understanding the mathematics helps us better understand the helper functions.

12

Conclusion

A brief history of Bezier curves and B-splines was presented, and in the context of Computer Aided Geometric Design, real world applications were proposed. We have reviewed the Bernstein polynomial and detailed Bezier curves in both the rational and non-rational case. Using a computer program created by the author, various images of Bezier curves were generated and screen captures included as examples. We have covered the rational and non rational, uniform and nonuniform, cases of B-splines. The Cox-de Boor algorithm was presented and computation of B-splines discussed in a detailed manner. A computer program was created and run to show the step by step computations performed by a B-spline computation. Tensor product surfaces were detailed in the Bernstein case, and the B-spline surface introduced. A sample data structure in the form of a display list from the authors OpenGL program was shown.

References
[1] Brian A. Barsky. Acm/siggraph 90 course 25: Parametric bernstein/bezier curves and tensor product surfaces, Dallas, TX. Aug. 7th 1990. [2] Robert C. Beach. An Introduction to Curves and Surfaces of Computer-Aided Design. Van Nostrand Reinhold, 1991. [3] Samuel R. Buss. 3D Computer Graphics A Mathematical Introduction with OpenGL. Cambridge University Press, 2003. [4] L. Piegl. Innite control points-a method for representing surfaces of revolution using boundary data. IEEE (Institute of Electrical and Electronics Engineers), March 1987. [5] C. Ramakrishnan. An introduction to nurbs and opengl, 2002. [6] Wayne Tiller. Rational b-splines for curve and surface representation. IEEE (Institute of Electrical and Electronics Engineers), September 1983.

13

You might also like