# Hexbyte News Computers Bézier Curves and Surfaces: the Utah Teapot

Hexbyte News Computers

Bézier Curves and Surfaces: the Utah Teapot

Keywords: Bézier curve, Bézier surface, parametric surface, Utah teapot, Newell, Bernstein polynomials, quadratic, cubic, Bézier basis matrix, De Casteljau algorithm, tesselation, Taylor series, forward difference, Bézier patch normal.

new_releases

Try out our new interactive applet at the bottom of this chapter.

## Hexbyte News Computers Newell’s Teapot

Figure 1: Newell’s original drawing of the teapot.

In 1975, computer researcher Martin Newell needed a new 3D model for his work. In these days of age, very few models where available to the computer graphics community and creating them was also far from easy. Most models had to get their points entered in the computer program by hand or with a graphics tablet (“a computer input device that allows hand-drawn images and graphics to be input. It may be used to trace an image from a piece of paper laid on the surface. Capturing data in this way is called digitizing”). The story goes that Newell drew a teapot he had at home and digitized these drawings to create the model we know today as the Utah Teapot (figure 1). The teapot is now usually available in rendering or modeling programs along with other geometric primitives, such as spheres, cubes, tori, etc. The walking teapot toys given by Pixar at SIGGRAPH since 2003 in tribute to Newell’s work and his iconic teapot, have even become a cult phenomenon (figure 2).

Figure 2: Pixar’s RenderMan walking teapot. A tribute to Newell’s work and iconic teapot.

One of the interesting properties of the teapot created by Newell is that the mathematical model used to define the surface of the object is very compact. The teapot contains 32 patches each defined by 16 points (the original data set contains 28 patches). You might wonder: “how it is possible to create a complex and smooth shape such as the teapot with such few points?”. The main idea of the technique is that these 16 points do not define the vertices of polygons as with the polygon mesh we have studied in the previous section. They represent the control points of something like a grid or lattice that influence the shape of an underlying smooth surface. You can see these points as magnets that push or pull the underlying surface. The surface itself actually doesn’t exist as such. To visualise it, we need to compute it by combining together these 16 controls point weighted by some coefficients. Because the creation of the surface is based on equations it falls under the category of parametric surfaces. The model used by Newell for the teapot (as many other types of parametric surface exist) is called a Bézier surface (or Bézier curve for curves). It was first described by Pierre Bézier in 1962. The principle of this technique is easier to understand with curves than with surfaces. Its application to 3D surfaces though is straightforward.

## Hexbyte News Computers Bézier Curve

To create a Bézier curve we only need 4 points. These point are control points defined in 3D space. As with surfaces, the curve itself doesn’t exist until we compute it by combining these 4 points weighted by some coefficients.

Figure 3: a Bézier curve and its 4 control points.

How do we compute this curve? Parametric curves are curves which are defined by an equation. As with every equation, this equation has a variable, which in the case of parametric curve, is called a parameter. Generally, this parameter is given the letter (t). In figure 4 for example, we have plotted the equation of a parabola (y=t^2). As with the example of the parabola, (t) doesn’t have to be contained within any specific range. It can as well go from minus to plus infinity. In the case of a Bezier curve though, we will only need value of t going from 0 to 1.

Figure 4: example of a parametric curve (plot of a parabola).

Evaluating the curve’s equation for values of (t) going from 0 to 1, is sort of the same as walking along the curve. It is important to understand that (t) is a scalar but that the result of the equation for any (t) contained in the range [0:1] is a position in 3D space (for 3D curves, and obviously a 2D point for 2D curves). In other words, if we need to visualise a parametric curve, all we have to do is to evaluate the curve’s equation for increasing values of (t) at some regular positions (it doesn’t have to be though), and connecting the resulting positions in space to create a polygonal path (as illustrated in figure 5).

Figure 5: legend a curve can be approximated by connecting a finite number of points on the curve using line segments to create a polygonal path.

With only 4 segments we can start to see what the overall shape of the curve looks like. To get a smoother result all there is to do is to increase the number of points and segments. This is in essence, how we will build and visualize Bézier curves. We will sample it at regular intervals and connect the point to create a series of connected line segments. The question now is how do we compute these positions? We mentioned before that shape of the curve was the result of the combining the control points weighted by some value (equation 1):

\$\$P_{curve}(t) = P1 * k_1 + P2 * k_2 + P3 * k_3 + P4 * k_4\$\$

where P1, P2, P3, P4 are the Bézier control points and (k_1), (k_2), (k_3), (k_4) are coefficients (scalar) weighting the contribution of the control points. Looking at figure 3, intuitively you can see that when (t) = 0, the first point on the curve coincides with the control point P1 (for (t) = 1, the end point coincides with P4). In other words you can write that:

\$\$
P_{curve}(t) = left{
begin{array}{ll}
P_{curve}(0)= P1 * 1 + P2 * 0 + P3 * 0 + P4 * 0\
P_{curve}(1)= P1 * 0 + P2 * 0 + P3 * 0 + P4 * 1\
end{array}
right.
\$\$

Now the parameter (t) appears nowhere in these equations. The value of (t) is actually used to compute the coefficients (k_1), (k_2), (k_3), (k_4) themselves with the following set of equations (equation 2):

\$\$
begin{array}{l}
k_1(t) = (1 – t) * (1 – t) * (1 – t)\
k_2(t) = 3(1 – t)^2 * t\
k_3(t) = 3(1 – t) * t^2\
k_4(t) = t^3
end{array}
\$\$

When we need to evaluate a position on the curve for a particular (t), we need to replace (t) in these four equations to compute the four coefficients (k_1), (k_2), (k_3), (k_4) which are then multiplied to the four control points. That gives us a position in 3D space for a given value of (t). If we wish to create a polygon path made out of 10 segments for instance, we compute 11 points by regularly incrementing (t) by 1/10. The following code example would compute these 11 positions along the curve:

int numSegments = 10;
for (int i = 0; i <= numSegments; ++i) { float t = i / (float)numSegments; // compute coefficients float k1 = (1 - t) * (1 - t) * (1 - t); float k2 = 3 * (1 - t) * (1 - t) * t; float k3 = 3 * (1 - t) * t * t; float k4 = t * t * t; // weight the four control points using coefficients point Pt = P1 * k1 + P2 * k2 + P3 * k3 + P4 * k4; }

Figure 6: