Chapter 7
Surface Modeling
7.1 Introduction
In a school, we have learned analytic representation of plane, sphere, cone (a general case
of cylinder), and torus. These primitive surfaces are widely used in CAD systems for the
design of mechanical components. Because of the importance of these primitive surfaces, their
representation and software implementation will be discussed in this chapter.
Although most mechanical parts can be modeled simply using planes, spheres, cones, and
toruses, many other geometric entities such as telephone handsets, car and airplane bodies,
and sculptures may not be represented by these primitive surfaces. In CAD systems,
Bézier and Bspline surfaces are used as the standard in industry for representing
freeform or sculptured surfaces. For this reason, Bézier and Bspline surfaces are
sometimes called freeform surfaces. In this chapter, we shall extend our knowledge
on Bézier and Bspline curves to surfaces. Although it is very involved in processing
a surface in terms of data arrangement and computation, the fundamental mathematics on
surfaces is directly derived from curves. If you have read through the previous chapter on
curve modeling and completed all examples, you will find that the underlying mathematics on
parametric surfaces is fairly straightforward. Virtually, you do not need any new algorithms
to evaluate Bézier and Bspline surfaces.
Bézier and Bspline surfaces are used in computer graphics and CAD systems for either
iterative design of geometric shapes or representation of prescribed surfaces. The latter
usually involves interpolation and approximation techniques. For example, to represent a
clay model of a car by Bspline surfaces we may collect a set of digitized data from the
clay model, then fit these digitized data by Bspline surfaces using interpolation or least
square approximation method. In this chapter, we cannot cover all surface construction methods
used for geometric shape design. Instead, we shall restrict ourselves to a number of essential
methods to construct ruled surfaces, surfaces of revolution, and swept surfaces and show you
how to use these techniques for interactive design of surfaces.
7.2 Primitive surfaces
In a middle school, we learned that a plane may be represented analytically by
where A, B, and C are some constants in the real field. Also a sphere may be given by
(xx_{0})^{2}+(yy_{0})^{2}+(zz_{0})^{2} =
r^{2}, 

where (x_{0}, y_{0}, z_{0}) are the center of the sphere and r the
radius. These representations are not very useful in CAGD application since they are
coordinate dependent. To avoid such shortcomings, the primitive surfaces are represented in
a vectorvalued parametric form. In what follows, we shall briefly discuss the vectorvalued
representation of plane, sphere, cone, and torus. We shall also show you how to create three
applets that let you display a sphere, cone, and torus.
Plane: An infinite plane is uniquely defined by a point p on the plane and a
unit normal e_{3} of the plane as shown in Figure 7.1.
Figure 7.1: A plane.
To represent a bounded (or a finite) plane, we need two additional unit vectors that furnish
the coordinate system, known as the frame, so that we can represent the plane
parametrically over some finite intervals. Let e_{1} and
e_{2} be two unit vectors such that e_{1}, e_{2},
and e_{3} are mutually orthogonal. Then, a finite plane may be defined as
S(u,v) = p + ue_{1} + ve_{2}, u Î [u_{min}, u_{max}], v Î [v_{min}, v_{max}]. 

In theory, we can choose an arbitrary e_{1} provided that
e_{1}·e_{3} = 0 (i.e., e_{1} is orthogonal
to e_{3}) and define e_{2} as
e_{2} = e_{3}×e_{1}. For numerical
stability, however, we suggest the following approach to choose e_{1}:
 Find the coordinate index i such that l = min{e_{3}^{1}, e_{3}^{2}, e_{3}^{3}}, where e_{3}^{1}, e_{3}^{2}, and e_{3}^{3} are the three coordinates of e_{3}.
 Let e_{1}^{i} = 1 and other coordinates of e_{1} be zero.
 Set e_{1} = e_{1}le_{3}.
 Normalize e_{1} to a unit vector, i.e., e_{1}/Ö{1l^{2}}.
Since l is the minimum absolute coordinate of e_{3}, it is then numerically stable to normalize e_{1}.
Implementing the above algorithm in Java gives
lambda = Math.abs(e_3.x);
e_1.x = 1.0;
e_1.y = e_1.z = 0.0;
if (lambda > Math.abs(e_3.y))
{
lambda = e_3.y;
e_1.y = 1.0;
e_1.x = 0.0;
}
if (lambda < Math.abs(e_3.z))
{
lambda = e_3.z;
e_1.z = 1.0;
e_1.x = e_1.y = 0.0;
}
temp = Math.sqrt(1  lambda * lambda);
e_1.x = (e_1.x  lambda * e_3.x) / temp;
e_1.y = (e_1.y  lambda * e_3.y) / temp;
e_1.z = (e_1.x  lambda * e_3.z) / temp;
The above algorithm will be used throughout this book to compute an orthogonal unit vector
with respect to another unit vector e_{3} whenever there is a need.
We now compute the first order partial derivatives. Differentiating S(u,v) with respect to u and v gives:

¶S ¶u

= e_{1}, 
¶S ¶v

= e_{2}. 

Accordingly, the surface normal is given by

¶S ¶u

× 
¶S ¶v

= e_{1}×e_{2} = e_{3}. 

Sphere: A sphere is uniquely defined by the center C and radius r of the
sphere. In order to represent a sphere in a vector space, we usually require the specification
of a unit vector e_{3} pointing from the center to the ``north pole''
(actually, an arbitrary point on the sphere) as shown in
Figure 7.2.
Accordingly, we may construct two unit vectors e_{1} and e_{2}
such that e_{1}, e_{2}, and e_{3} are mutually
orthogonal and hence represent the sphere in the local frame (i.e., e_{1},
e_{2}, and e_{3}) with origin coincides with the center of the
sphere. Let the angle parameter u Î [0,p]
be oriented from the south to the north pole and v Î
[0,2p] be, by default, oriented in accordance with the righthand
rule with respect to the vector e_{3} (see Figure 7.2). Then, projecting an
arbitrary point p onto the e_{3} axis and the
e_{1}e_{2} plane gives rcosu and rsinu respectively. If rsinu
is further projected onto the e_{1} and e_{2} axes, we obtain
respectively the coordinates on these two axes as rsinucosv and rsinusinv. Consequently, we
can write p in the local coordinate system as
p = rsinucosve_{1} + rsinusinve_{2}rcosue_{3} = rsinu(cosve_{1}+sinve_{2})rcosue_{3}. 

Since p is an arbitrary point on the sphere, the above equation is the representation of the sphere in the local frame. The representation of a sphere with center at C is thus given by
S(u,v) = C + rsinu(cosve_{1}+sinve_{2})  rcosue_{3}. 

Differentiating S(u,v) with respect to u and v gives the first order partial derivatives:

¶S ¶u

= rsinu(cosve_{1}+sinve_{2})+rsinu, 
¶S ¶v

= rsinu(sinve_{1}+cosve_{2}). 

Based on our discuss on a sphere, we now create the GSphere class that defines a
sphere and provides some member methods for evaluation. The source code GSphere is
listed as follows:
The above code is a direct implementation of the math equations discussed previous. Save the
above code under the name GSphere.java in the directory GeomLib and compile
it to get GSphere.class. Let us now create the applet ShowSphere to display
a predefine sphere. The code is listed below.
Save the above code in Ch6 and compile it to get ShowSphere.class. We can
then create a HTML file to invoke the applet.
Cone/Cylinder: A cone is defined by the base ellipse r(v) and the major half
angle aÎ [0,p/2)
as shown in Figure 7.3.
Let u be the arc length parameter along the the direction of the normal of the base ellipse.
Then, the scale factor for an ellipse at u to the base ellipse is
where, a is the length of the major axis of the base ellipse. Accordingly, the cone is represented as
S(u,v) = C+ 
æ ç
è

1 + 
u a

tana 
ö ÷
ø

(r(v)c) + lun, 

where l = ±1. If the u increase in the direction of the normal of the base ellipse, l = 1. Otherwise, l = 1.
Differentiating S(u,v) with respect to u and v gives the first order partial derivatives:

¶S ¶u

= 
1 a

tana(r(v)c)+lun, 
¶S ¶v

= (1+ 
u a

tana) r^{¢}(v). 

Based our discuss on cones, we now create the GCone class that defines a cone and
provides some member methods for evaluation. The source code of GCone class is
listed as follows:
The above code is a direct implementation of the math equations discussed previously. Let's
save it in the directory GeomLib and compile it to get GCone.class. We
design the applet ShowCone that allows you to display the predefined cone. You
can also click the scroll bar on the applet to change the angle a
so as to obtain different cones. The source code of the ShowCone is given below.
Save the code in the directory Ch6 and compile it to get ShowCone.class.
Then, write a HTML file to invoke the applet.
Torus: A torus is generated by moving a minor (or outside) circle along a major (or
inner circle) with the center of the minor circle on the major circle as shown in
Figure 7.4.
We denote the center, radius, and unit normal of the major circle respectively by
C, R, and e_{3}. If this major circle is parametrized by v in radian,
we assume that the flow direction of v agrees with the righthand rule with respect to the
normal e_{3}. We also denote the radius and parameter of the minor circle by
r and u. In order to represent the torus in a vectorvalued parametric form, we choose two
unit vectors e_{1} and e_{2} such that e_{1}, e_{2}, and e_{3} are mutually orthogonal. Accordingly, the three unit vector and the center of the major circle furnish the local frame.
For v = 0, an arbitrary point on the torus in the local frame is given by
p = (R+rcosu)e_{1}+rsinue_{3}. 

If this point is rotated about the axis e_{3} by an angle v, the coordinate
on e_{3} does not change. Accordingly, we have
p = (R+rcosu)(cosve_{1}+sinve_{2})+ rsinue_{3}. 

Since p is an arbitrary point on the torus, the above equation is the representation
of the torus in the local frame. The torus in the global coordinate system is thus
represented by
S(u,v) = c+(R+rcosu)(cosve_{1}+sinve_{2})+ rsinue_{3}. 

Differentiating S(u,v) with respect to u and v gives the first order partial derivatives:

¶S u

= rsinu(cosve_{1}+sinve_{2})+rcosue_{3}, 
¶S v

= (R+rcosu)(sinve_{1}+cosve_{2}). 

Based our discussion on torus, we now create the GTorus class that define a torus
and provides the evaluation methods. The source code is given below.
The above code is a straightforward implementation of the math equations discussed previously.
Save this code in the directory GeomLib and compile it to get GTorus.class.
We then design the ShowTorus class that allows you to display a torus and change the
radius of the major circle by clicking the scroll bar. The source code is listed as follows.
7.3 Mathematical background on Bézier Surface
If you have gone through the section of Mathematical background on Bézier curve,
then you will find the underlying mathematics for a Bézier surface is fairly
straightforward.
We start our discussion with a straight line. Representing the straight line by a
Bézier curve of degree one (i.e., order 2) defined over v Î
[0,1] gives
S(v) = p_{0} (1v)+p_{1} v, 

where, p_{0} and p_{1} are two end points on the line.
Rather than considering p_{0} and p_{1} as fixed points,
we may take them to be the locus of other two Bézier lines defined over u
Î [0,1], i.e.,
p_{0}(u) = p_{0,0}(1u)+p_{1,0}u 

and
p_{1}(u) = p_{0,1}(1u)+p_{1,1}u. 

Replacing p_{0} and p_{1} in S(v) by
p_{0}(u) and p_{1}(u), we obtain a Bézier plane defined
by four control vertices p_{0,0}, p_{1,0},
p_{0,1} and p_{1,1} over the parametric domain
[0,1]×[0,1], i.e.,
S(u,v) = (p_{0,0}(1u)+p_{1,0}u)(1v)+ (p_{0,1}(1u)+p_{1,1}u)v. 

The above constructive description about surface is applicable to a generic Bézier surface as well. Let a Bézier curve of degree m defined over v Î [0,1] be denoted by
S(v) = 
m å
j = 0

p_{j} B_{j,m}(v), (71) 

where, B_{i,m}(v) are the Bernstein polynomials of degree m. Similarly, we may consider p_{j} to be the locus of a Bézier curve of degree n defined over u Î [0,1], i.e.,
p_{j}(u) = 
n å
i = 0

p_{i,j} B_{j,n}(u), 

where, B_{i,n}(u) are the Bernstein polynomials of degree n. Replacing p_{j} in equation (71) by p_{j}(u) defines a Bézier surface of degree n in u and m in v:
S(u,v) = 
m å
j = 0


æ è

n å
i = 0

p_{i,j} B_{i,n}(u) 
ö ø

B_{j,m}(v). (72) 

The control vertices p_{i,j} form the control polyhedron of a Bézier surface. It is readily derived from the above equation that:
 For a fixed u parameter, å_{i = 0}^{n} p_{i,j}B_{i,n}(u) are constant and denoted by p_{j}. Hence, S(u,v) = å_{j = 0}^{m} p_{j} B_{j,m}(v) is a Bézier curve in v and is called the isou curve.
 We rewrite the surface as
S(u,v) = 
n å
i = 0


æ è

m å
j = 0

p_{i,j} B_{i,m}(v) 
ö ø

B_{j,n}(u). 

Then, for a fixed v parameter, å_{j = 0}^{m} p_{i,j}B_{i,m}(v) are constant and denoted by p_{i}. Therefore, S(u,v) = å_{i = 0}^{n} p_{i} B_{i,n}(u) is a Bézier curve in u and is called the isov curve.
We now consider the evaluation of Bézier surfaces. Mathematically speaking, we do not
need a new algorithm to evaluate a point on a Bézier surface with respect to the given
u and v parameters. We can use the bases evaluation method discussed in the section of
Mathematical background on Bézier curve to compute the basis functions
B_{i,n}(u) and B_{j,m}(v). Let BFunct_u[i] and BFunct_v[j]
store B_{i,n}(u) and B_{j,m}(v) respectively. Then, the point on the
Bézier surface is computed as follows:
rx = ry = rz = 0.0;
for (j=0; j<=m; j++)
{
for (i=0; i<=n; i++)
{
temp = BFunct_u[i] * BFunct_v[j];
rx += x[j][i] * temp;
ry += y[j][i] * temp;
rz += z[j][i] * temp;
}
}
noting that x[j][i], y[i][j], and z[i][j] denote the Cartesian
coordinates of p_{i,j}.
It is also true that we do not need a new algorithm to subdivide a Bézier surface. For
example, if we want to subdivide the surface given in (72) at u = 0.5, we simply call the
SubdivideCurve() method discussed in the previous chapter to halve

n å
i = 0

p_{i,j}B_{i,n}(u), j = 0,1,¼, m 

which are Bézier curves in u. Denoting the control vertices of the lefthalved and righthalved by p_{i,j}^{1} and p_{i,j}^{2} respectively, we can write (72) as
S(u,v) = å_{j = 0}^{m}(å_{i = 0}^{n}p_{i,j}^{1} B_{i,n}(u)+ å_{i = 0}^{n}p_{i,j}^{2} B_{i,n}(u))B_{j,m}(v)
= å_{j = 0}^{m}(å_{i = 0}^{n}p_{i,j}^{1} B_{i,n}(u))B_{j,m}(v)+ å_{j = 0}^{m}(å_{i = 0}^{n}p_{i,j}^{2} B_{i,n}(u))B_{j,m}(v).
As it is seen, the surface is now subdivided into two.
Analogous to a rational Bézier curve, a rational Bézier surface is given by
S(u,v) = 
m å
j = 0


æ è

n å
i = 0

w_{i,j}p_{i,j} B_{i,n}(u) 
ö ø

B_{j,m}(v) 
m å
j = 0


æ è

n å
i = 0

w_{i,j} B_{i,n}(u) 
ö ø

B_{j,m}(v) 

, 

where w_{i,j} are again the weights. Evaluation and subdivision of a rational Bézier surface is the same as those for a polynomial Bézier surface provided it is represented in homogeneous coordinates.
We now move to the next section to design an applet that allows you to display and manipulate a Bézier surface.
7.4 Creating Bézier surface applet
We have learned the mathematics on Bézier surfaces. Therefore, it is time for us to put the math in action. In particular, we shall create an applet that allows you to display a predefined Bézier surface and manipulate the control vertices to redesign the shape of the surface.
Let us first implement the GBezierSurface class that defines a Bézier surface and provides member methods for data setting and geometric processing. Similar to the GBezierCurve class, an onedimensional array is used in GBezierSurface class to store the control vertices of a Bézier surface as shown below:
poles[]={x_{00},x_{10},¼,x_{n0},¼,x_{0m},x_{1m},¼, x_{nm}, y_{00},y_{10},¼,y_{n0},¼}
Therefore, there are (m+1)×(n+1) elements for each dimension. The source code of
GBezierSurface is listed as follows.
As you may note, we did not implement a method to evaluate the Bézier basis functions.
This is because the computation of basis functions for a surface is the same as that for a
curve. Therefore, when there is a need to evaluate the Bézier basis functions, we can
create a Bézier curve object to access its member method EvalBases() defined
in the GBezierCurve class. Since this curve object does not hold any control
vertices, we may consider it as a ``dummy'' object. Save the above code under the name
GBezierSurface.java in the GeomLib directory and compile it to get
GBezierSurface.class.
Let us now design an applet that allows you to display and manipulate a predefined
Bézier surface with option to change the density of grids. We call this applet the
ShowBezSurf and type the following code.
What we need to emphasize in the above code is the way to display the control polyhedron
and the resulting surface. The polyhedron is shown by plotting the polygons first in
udirection, then in v direction. The surface is displayed by plotting a number of isov
curves and then isou curves. Therefore, the surface is actually seen through isocurves
that form the grids (or meshes) on the surface. This is an inexpensive method to visualize
the surface. Save the above code under the name ShowBezSurf.java in the directory
Ch6 and compile it to get ShowBezSurf.class. Then, we write a HTML file
to invoke the applet. If everything works fine, you should see an applet simialr to that in
Figure 7.5.
In CAGD applications, we often encounter a case where the shape of a single Bézier
surface is not rich enough to describe a complicated geometric object (e.g., a arc body).
One solution to such a problem is to blend a number of Bézier surfaces together with
some constraints. The surface that is made of several Bézier surfaces is called a
composite Bézier surface. Although a composite Bézier surface can meet the
requirement of describing a complicated geometric shape, it is often not preferred in
applications since it usually requires more control vertices than a Bspline surface does.
Therefore, let us move to the next section to study the mathematics on Bspline surfaces.
7.5 Mathematical background on Bspline Surface
In the previous chapter, we have seen that Bspline curves provide a very useful way of generating smooth curves from a small number of control vertices in comparison with a composite Bézier curve. Therefore, Bspline curves are widely used in industry for modeling freeform curves. Bspline surfaces are related to Bspline curves in the same way that Bézier surfaces are related to Bézier curves. If you have gone through the sections of Mathematical background on Bspline curve and Mathematical background on Bézier Surface, you will find the content of this section is fairly understandable.
Let a Bspline curve of order k_{v} with q control points be given by
S(v) = 
q1 å
j = 0

d_{j} N_{j,kv}(v), 

where, d_{j} are the control vertices that form the control polygon of a Bspline curve and N_{j,kv}(v) are the Bspline basis functions defined by the v knot vector. Rather than considering the control vertices d_{j} to be stationary points, we may take them to be the locus of the following Bspline curve of order k_{u} with p control points:
d_{j} = d_{j}(u) = 
p1 å
i = 0

d_{i,j}N_{i,ku}(u), 

where, N_{i,ku}(u) are the Bspline basis functions defined by the u knot vector. Replacing d_{j} in S(v) by d_{j}(u) defines a Bspline surface of the form:
S(u,v) = 
q1 å
j = 0


æ è

p1 å
i = 0

d_{i,j} N_{i,ku}(u) 
ö ø

N_{j,kv}(v). (73) 

The control vertices d_{i,j} form the socalled control polyhedron of a Bspline surface. It is readily derived from equation (73) that:
 For a fixed u parameter, å_{i = 0}^{p1} d_{i,j} N_{i,ku}(u) are constant and denoted by d_{j}. Hence, S(u,v) = å_{j = 0}^{q1} d_{j} N_{j,kv}(v) is a Bspline curve in v and is called the isou curve.
 We rewrite the surface as
S(u,v) = 
p1 å
i = 0


æ è

q1 å
j = 0

d_{i,j} N_{i,kv}(v) 
ö ø

N_{j,ku}(u). 

Then, for a fixed v parameter, å_{j = 0}^{q1} d_{i,j}N_{i,kv}(v) are constant and denoted by d_{i}. Therefore, S(u,v) = å_{i = 0}^{p1} d_{i} N_{i,ku}(u) is a Bspline curve in u and is called the isov curve.
We now consider the evaluation of Bspline surfaces. Mathematically speaking, we do not need a new algorithm to evaluate a point on a Bspline surface. Assume that we want to evaluate a Bspline surface with respect to the parameters u Î [u_{ju}, u_{ju+1}) and v Î [v_{jv}, v_{jv+1}). We then use the basis evaluation method discussed in the section of Mathematical background on Bspline curve to compute the basis functions N_{i,ku}(u) and N_{j,kv}(v). Due to the local support property of Bsplines, the nonvanishing basis functions are N_{juku+1}(u),¼, N_{ju}(u) and N_{jvkv+1}(v),¼, N_{jv}(v). Therefore, the point on the surface is given by
p = 
k_{v}1 å
j = 0


k_{u}1 å
i = 0

d_{ juku+1+i, jvkv+1+j} N_{juku+1}(u) N_{jvkv+1}(v). 

It is also true that we do not need a new algorithm to insert a knot into the existing u and v knot vectors of a Bspline surface. Suppose that we want to insert a new knot, say [`u], into the u knot vector of the surface given in (73) such that there are m [`u] in the existing u knot vector. We then simply apply the same knot insertion algorithm discussed in the section of Mathematical background on Bspline curve to each Bspline curve

p1 å
i = 0

d_{i,j}N_{i,ku}(u), j = 0,1,¼, q1. 

In the next section, we shall create an applet that allows you to insert a knot into the existing u knot vector. By then, you will have a chance to study the implementation of the knot insertion technique in detail.
Analogous to a rational Bspline curve, a rational Bspline surface is given by
S(u,v) = 
q1 å
j = 0


æ è

p1 å
i = 0

w_{i,j}d_{i,j} N_{i,ku}(u) 
ö ø

N_{j,kv}(v) 
m å
j = 0


æ è

p1 å
i = 0

w_{i,j} N_{i,q1}(u) 
ö ø

N_{j,kv}(v) 

, 

where w_{i,j} are again the weights. Rational Bspline surfaces are also known as the NURBS (NonUniform Rational BSpline) surfaces. Evaluation and knot insertion of a rational Bspline surface is the same as those for a polynomial Bspline surface provided it is represented in homogeneous coordinates.
Enough for the math. Let us move to the next section to design two applets that allow you to display and manipulate Bspline surfaces.
7.6 Creating Bspline surface applet
In this section, we shall create two applets that allow you to display and manipulate Bspline surfaces. Before doing so, we first need to implement the GBsplineSurface that defines a Bspline surface and provides member methods for data setting and geometric processing. In order to make the GBsplineSurface flexible enough to deal with both polynomial and rational surfaces, we use an onedimensional array to store the control vertices, i.e.,
poles[]={x_{0,0},x_{1,0},¼,x_{p1,0},¼,x_{0,q1}, x_{1,q1}, ¼, x_{p1,q1}, y_{0,0},y_{1,0},¼, y_{p1,0}, ¼}
Therefore, there are p×q elements for each dimension. The actual source code of GBsplineSurface is listed below.
Similar to the way we implemented GBezierSurface, we also create ``dummy'' Bspline
curve objects to access member methods defined in the GBsplineCurve class, which
avoids duplication of the same code. The EvalPoint() and EvalIsoCurve()
methods are simply the implementation of the method discussed in the previous section. Save
this code under the name GBsplineSurface.java in the GeomLib directory and
compile it to get GBsplineSurface.class.
We now create the first applet ShowBspSurf that displays a Bspline surface with
option to choose the density of grids. It should be pointed out that the GBsplineSurface
class can handle generic polynomial Bspline surfaces. For simplicity, however, the surface in
ShowBspSurf applet is predefined. When you understand the implementation detail, you
can either modify or create a new applet that allows you to generate a sophisticated Bspline
surface. Let us type the following code.
Save the code under the name ShowBspSurf.java in the directory Ch6 and
compile it to get ShowBspSurf.class. Then, we write a HTML web page to invoke the
applet. If everything is okay, you should be able to see an applet similar to that in
Figure 7.6.
The Bspline surfaces in the applets are created by specifying the control vertices that form
the control polyhedrons of the surfaces. In subsequent sections, we shall show you some
important surface construction methods that start by designing curves then extend them to
generate ruled surfaces, surfaces of revolution, and swept surfaces.
7.7 Ruled surface
Given two curves r_{1}(u) and r_{2}(u), a ruled surface is
generated by moving a straight line joining corresponding points on two curves. Mathematically,
a ruled surface is a linear blending surface between two curves, i.e.,
S(u,v) = r_{1}(u)+v[r_{2}(u)r_{1}(u)] 

where, v varies in [0,1]. The two curve r_{1}(u) and r_{2}(u) can be any form of parametric curves such as ellipse, circle, Bézier, or Bspline curves.
Differentiating S(u,v) with respect to u and v gives the first order partial derivatives:

¶S ¶u

= r_{1}^{¢}(u)+v(r_{2}^{¢}(u)r_{1}^{¢}(u)) and 
¶S ¶v

= r_{2}(u)r_{1}(u). 

In what follows, we shall design an applet that allows you to create different ruled surfaces by manipulating two Bspline curves r_{1}(u) and r_{2}(u). Let us first define the GRuledSurface class of which the source code is given below.
The GRuledSurface class has two member variables bspcv1 and bspcv2
that define the ruled surface. The member method UpdateCurve is used to update one
of the base curves. The EvalPoint method evaluate a point on the surface with
respect to the given u and v parameters. Finally, the EvalIsovCurve method computes
a set of points with respect to given v. It is noted that we do not need a method to evaluate
isou curves since they are straight lines. Save the above code under the name
GRuledSurface.java in the directory GeomLib and compile it to get
GRuledSurface.class.
We now design the applet ShowRuleSurf that has two buttons Design Curve and
Create Surface. When you click on the Design Curve button, you can
manipulate the predefined Bspline curves. When you are satisfied with the shapes of two
curves, you then click the Create Surface to construct a ruled surface. The source
code is given as follows.
We save the above code under the name ShowRuleSurf.java in the directory Ch6
and compile it to get ShowRuleSurf.class. Then, write a HTML web page
ShowRuleSurf.html to invoke the applet which looks similar to
Figure 7.7.
7.8 Surface of revolution
A surface of revolution is generated by rotating a curve r(u) about an axis defined
by a point q on the axis and the direction vector e_{3}. Therefore,
for any given u, the locus of a surface of revolution is a circular arc in v. By default,
the v parameter increases in the direction that follows the righthand rule with respect to
e_{3}. To represent a surface of revolution parametrically, we need to define
a local frame (or a local coordinate system). For the purpose of numerical stability, it is
desirable to find a point p on the curve r(u) such that this point has the
largest distance to the axis. Projecting this point onto the axis obtains a point
s. Let
e_{1} = 
ps 
ps 

, e_{2} = e_{3}×e_{1}.


Then, e_{1}, e_{2}, and e_{3} furnish the vector
bases for our local coordinate system. It should be noted that, in practice, we want an
inexpensive method to determine a point on the trace curve such that we can build a unit
vector e_{2} from this point. One approach is to compute p = r(u)
at u = 0.5. If the distance from p to the axis is greater than the distance tolerance,
p is valid. Otherwise, we take u to be some other value until we obtain a valid
p.
Let C(u) = r(u)s. Then, the three coordinates of
C(u) in the local frame are given by
E_{1}(u) = C(u)·e_{1}, E_{2}(u) = C(u)·e_{2}, E_{3}(u) = C(u)·e_{3}. 

Therefore, the trace curve in the local coordinate system is given by
C(u) = E_{1}(u)e_{1} + E_{2}(u)e_{2} +
E_{3}(u)e_{3}. 

When C(u) is rotated about the axis e_{3} by an angle v, the
coordinate on the e_{3} axis (i.e., E_{3}(u)) is not affected.
Furthermore, if C(u) is project onto the e_{2} e_{3}
plane, the magnitude (or length) of the projected C(u) is irrespect to the rotation.
Therefore, we can derive the representation of the surface of revolution as follows:
S(u,v) = s + E_{1}(u)(cosve_{1}+
sinve_{2}) + E_{2}(u)(sinve_{1}+cosve_{2
}) + E_{3}(u)e_{3}
= s+(E_{1}(u)cosvE_{2}(u)sinv)e_{1} + (E_{1}(u)sinv+E_{2}(u)cosv)e_{2} + E_{3}(u)e_{3}
If we differentiate S(u,v) with respect to u and v, we then obtain the first order
partial derivatives:
[(¶S)/(¶u)] = (E_{1}^{¢}(u)cosvE_{2}^{¢}(u) sinv )e_{1} +(E_{1}^{¢}(u)sinv + E_{2}^{¢}(u)cosv)e_{2} + E_{3}^{¢}(u)e_{3},
[(¶S)/(¶v)] = (E_{1}(u)sinv+E_{2}(u)cosv)e_{1}+(E_{1}(u)cosv
E_{2}(u)sinv)e_{2},
where E_{1}^{¢}(u) = C^{¢}(u)·e_{1} = r^{¢}(u)·e_{1},
E_{2}^{¢}(u) = r^{¢}(u)·e_{2}, and E_{3}^{¢
}(u) = r^{¢}(u) ·e_{3}.
Having understood the mathematics on a surface of revolution, we can now design the
GRevolSurface class of which the code is given below:
A surface of revolution is defined by a profile curve and an axis which in turn is defined by
a base point and the direction vector e_{3}. Therefore, the
GRevolSurface class has respectively three member variables bspcv,
basePoint, and e_3. We also declare three additional member variables
e_1, e_2 and sigma that represent e_{1},
e_{2}, and s. They are declared as private
since there is no need for users to be involved with them. Similar to other geometric
surfaces classes, we have some member methods that deal with updating and evaluating. Save
the above code under the name GRevolSurface.java in GeomLib and compile
it to get GRevolSurface.class.
Let's create the applet ShowRevSurf that allows us to generate and manipulate
surfaces of revolution. The source code of ShowRevSurf is given below.
We save the above code under the name ShowRevSurf.java in the directory
GeomLib and compile it to get ShowRevSurf.class. We then write a HTML web
page named ShowRevSurf.html to invoke the applet. If verything works well, we should
see an applet similar to that in Figure 7.8.
7.9 Swept surface
A swept surface is created by moving a given section curve C(v) along a prescribed
curve (i.e., a trace or trajectory curve) r(u) with the origin of the section curve
coinciding with the trace curve r(u). Let t(u), n(u), b(u)
be three mutually orthogonal unit vectors associated with the trace curve r(u), then
the swept surface is given by
S(u,v) = r(u)+[C(v)·t(u)]t(u)+[C(v)·n(u)]n(u)+[C(v)·b(u)]b(u). 

If r(u) is a regular curve (i.e., the first derivative of r(u) dose not
vanish), we may choose t(u), n(u), b(u) to be the Frenet frame.
Accordingly, we have
t(u) = 
r^{¢}(u) r^{¢}

, n(u) = t(u)×k, b(u) = n(u)×t(u), 

where, r^{¢}(u)
 = Ö{r^{¢
}(u)·r^{¢}(u)}.