Documente Academic
Documente Profesional
Documente Cultură
Fredrik Andersson
fmu@home.se
Supervisor:
Berit Kvernes
beritk@cs.umu.se
Abstract
Graphical curves and surfaces are hot topics in many different areas of research and application, not least due to the rapid progression of computer
aided design (CAD) and gaming technology. Two of the most popular representations for this field are the Bezier and B-spline curves and surfaces.
This thesis will describe the theory behind these topics from a programmers viewpoint, together with the developed software which is a rather intuitive application to model different types of Bezier and B-spline curves and
surfaces in real-time.
The mathematics behind these elements can be quite intimidating to
the normal user at first, hence this thesis is dedicated to students with
some background in elementary linear algebra and variable calculus but not
necessarily in computer graphics.
There are an abundance of interesting aspects to this topic of curves
and surfaces, and this thesis will primarily focus on the different ways to
use, implement and efficiently evaluate them. Thus, this report will serve as
excellent material for students entering the field of polynomial curves and
surfaces in computer graphics.
Acknowledgements
I would like to thank my supervisor Berit Kvernes for the great support,
both morally and technically. Also, love goes to my parents which have
assisted with finance, corrective reading and moral support.
Francois Rimasson, 3D-artist, and Andreas Johansson, fellow student,
supplied me with superb visual material for the presentation of my work.
This was very appreciated and I thank both of you.
Contents
1 Introduction
1.1 Background . . . . . . . .
1.2 Objective . . . . . . . . .
1.3 Structure of the thesis . .
1.4 Prerequisites . . . . . . .
1.5 Software . . . . . . . . . .
1.6 Notation and Typesetting
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
9
9
10
10
11
11
11
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
13
13
15
16
17
18
18
19
20
20
21
21
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
23
23
24
26
27
27
30
30
31
31
32
33
3.9 Concatenation . . . . . . . . . .
3.10 Other spline forms . . . . . . . .
3.10.1 Natural spline . . . . . . .
3.10.2 Hermite curves . . . . . .
3.10.3 Catmull-Rom splines . . .
3.10.4 Uniformly shaped -spline
3.11 B-spline summary . . . . . . . .
4 Applications
4.1 Camera movement .
4.2 Topologies . . . . . .
4.3 Character movement
4.4 Collision detection .
4.5 Soft objects . . . . .
4.6 Automatic LOD . .
4.7 Object modeling . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
34
34
35
35
35
36
36
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
37
37
38
39
39
42
43
43
5 Implementation
5.1 Simple evaluation . . . . . .
5.2 Forward difference . . . . .
5.3 Recursive subdivision . . .
5.4 Look-up tables . . . . . . .
5.5 Portability . . . . . . . . . .
5.6 Implementation comparison
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
45
45
45
46
47
47
48
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6 Closing remarks
53
6.1 Personal comments . . . . . . . . . . . . . . . . . . . . . . . . 53
6.2 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
6.3 Using the software . . . . . . . . . . . . . . . . . . . . . . . . 54
List of Figures
2.1
2.2
2.3
2.4
2.5
2.6
2.7
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
14
14
15
16
17
19
20
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
3.10
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
24
24
25
26
27
28
29
31
33
35
4.1
4.2
4.3
4.4
4.5
4.6
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
37
38
40
41
42
43
5.1
5.2
5.3
5.4
5.5
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
48
49
50
51
52
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Chapter 1
Introduction
Over the last two decades the scene of computer graphics has literally exploded with progress in all directions; the arrival of dedicated 3D hardware,
computer generated animation and faster computers to name a few key
events.
One of these directions focus on displaying smooth curves and surfaces,
suitable for modeling landscapes, faces and other topologies of interest. Here
arise the need for Bezier and, in particular, B-spline curves, two concepts
with roots in the late 1950s.
These two types of curves are made up of an arbitrary amount of control
points which provide a guideline for the evaluated curve to approximate.
The approximation can be modified to suit its needs in a number of different
ways; weighted control points, knot vectors, varying the degree of the curve,
and so forth. All will be expanded on and explained later.
One might ask why parametric representations of curves and surfaces
are to prefer over the polygonal representation. A few good reasons are
tiny size, automatic detail resolution and scalability1 . The advantages are
numerous and will be thoroughly investigated.
1.1
Background
Before the 1950s, designing smooth shapes was a very tedious effort. Environment dependent aluminum strips, clumsy full scale moulding forms and
a timetable that would havoc most modern companies.
In 1959, an employee at the Citroen automobile company named Paul
de Faget de Casteljau came up with the simple idea of iterating affine combinations of polygon meshes to obtain smooth surfaces suitable for modeling
car chassis. Almost simultaneously, Peugeot employee Pierre Bezier worked
on the intersection of partial cylinders to achieve the same goals. Both versions, which produced equal curves, are today known as the Bezier curve
1
since Pierre Bezier was the first to write a public paper on the subject. Paul
de Faget de Casteljau was however not forgotten, as his named is etched in
the Casteljau algorithm, one of the most common ways to evaluate Bezier
curves. Both of these methods, and their extensions to other curves, are
explained in later sections.
The Bezier curve was formally presented in [9] and has since then been
a very common way to display smooth curves, both in computer graphics
and mathematics.
The B-spline curve is an extended version of the Bezier curve that consists of segments, each of which can be viewed as an individual Bezier curve
with some additions that will be covered in chapter 3.
1.2
Objective
The purpose of this thesis is to thoroughly investigate and explain the concept, use and implementation of Bezier and B-spline curves and surfaces to
readers with little experience in the field. This is accomplished primarily
with the report, but also practically aided from the developed software.
There are a number of issues that perplexes the use of parametric curves
or surfaces in computer graphics. With no priorities, to name a few:
Since computer graphics and gaming technology are appreciated topics with
most computer science students (and hence, readers of this thesis), these
areas will serve as a guideline for the report.
1.3
Mathematics are fundamental to parametric curves and surfaces, so the report begins with a very thorough explanation of the Bezier and B-spline
curve concepts and the related topics of interest (Hermite curves, for instance). Figures are used extensively to demonstrate and simplify the theories, with some references to the developed thesis application.
Further on, sections on the actual use of curves and surfaces in the real
world followed by some discussion of advantages and disadvantages with the
contemporary representations.
2
10
The vast field of implementation options are covered at the end of the
thesis, together with some discussions about efficiency, collision detection
and related topics.
1.4
Prerequisites
It is assumed that the reader of this thesis has studied elementary linear
algebra, some multivariate calculus and maybe a dash of computer graphics.
The two latter are not really necessary, but improves the understanding of
the underlying mathematics and theories.
1.5
Software
1.6
This report uses standard LATEX. Also, the concept of C x and Gx continuity
levels are used extensively, and should be familiar to the reader as I have
observed no other formats for describing continuity in the realms of computer
graphics.
11
12
Chapter 2
2.1
Basis function
A cubic Bezier curve consists of four control points used to position and
modify the curve, P0 through P3 . The two intermediate points P1 and P2
are used to specify the endpoint tangent vectors, hence the curve interpolates (passes through) P0 and P3 while approximating the other two control
points. To accomplish this we need some sort of weighting function which
tells us the influence of the control points at a given point on the curve. One
can use an arbitrary function to suit the requirements but in most cases we
define the Bernstein polynomials [1][2]
Bi,n (u) =
or similarly
Bi,n (u) =
n i
u (1 u)ni
i
n!
ui (1 u)ni
i!(n i)!
(2.1)
(2.2)
where i is the control point to be weighted and n is the degree of the curve,
to be the basis function. As we can see in figure 2.1-2.3 these polynomials are
symmetric and sum to unity. The resulting Bezier curve is also symmetric,
as can be seen in figure 2.4, hence the evaluation direction does not matter.
Since the understanding of the basis function is crucial to grasp this
report, we will now expand on the topic.
13
polynomials look). The basis functions used in this figure are B0,2 , B1,2 and
B2,2 .
It is perhaps suitable to mention that there is no local control this far.
Moving one control points affects the entire curve.
influence
1
2.2
Curve definition
Now that we are familiar with the Bezier basis functions, here is the definition of a Bezier curve of degree n
C(u) =
n
X
Pi Bi,n (u)
(2.3)
i=0
To evaluate the curve at u (0, 1) we simply iterate the n+1 control points
and compute the corresponding influence. This can also be expressed in
matrix form for those more familiar with linear algebra.
C(u) = U MB GB
(2.4)
where U is a vector of [un , un1 , . . . , u, 1], MB the Bezier basis matrix and
GB is a vector with the n+1 control points. The first, more analytical
15
2.3
Curve segments
2.4
Bezier subdivision
If a Bezier curve is not flexible enough, we can break the curve at a given
point u0 and create two new Bezier curves that join on u0 . An algorithm
for this task was presented by de Casteljau [8], and it uses a geometric
construction technique.
More formally, this involves finding points L0 , L1 , L2 , L3 and R0 , R1 , R2 , R3
so that the Bezier curve formed by L exactly matches 0 u < 0.5 of the
original curve, and R matches 0.5 u 1.0. Since L and R are separate
curves, they are both evaluated locally with 0.0 u 1.0.
Assume that our original Bezier curve consists of P0 , P1 , P2 , P3 . We then
construct a point H that divides P0 P1 , P1 P2 and P2 P3 in a ratio of (1 u0 ).
This creates a hull with points L0 L1 L2 L3 and R0 R1 R2 R3 , and we have two
sets of control points that lie in the hull of the original control points since
L and R are weighted sums of P .
This basically is the de Casteljau algorithm which is covered in section
2.7.
17
2.5
Rational curves imply that each of the control points are extended with one
coordinate which represents the weight or amount of influence. A heavy
vertex will draw the curve towards it, and a light vertex (can be negative as
well) will push the curve away.
This is of great importance when designing curves on the computer
screen, which has a limited area. Instead of dragging the control point
far away, perhaps outside the canvas, we can simply increase the weight.
The extension does not require much calculation and we now have:
Pn
wi Pi Bi,n (u)
C(u) = Pi=0
n
i=0 wi Bi,n (u)
(2.5)
where wi is the weight of Pi . Both sums can be calculated within the same
iteration of the control points, so for very little processing time we obtain a
curve which is far more useful.
2.6
Bezier surfaces
The Bezier surface is simply an extension of the Bezier curve in two parametric directions, a tensor product of two curves. It is evaluated through
C(u, v) =
n X
m
X
(2.6)
i=0 j=0
Pn
Pm
i=0
j=0 wi,j Pi,j Bi,n (u)Bj,m (u)
Pn Pm
i=0
j=0 wi,j Bi,n (u)Bj,m (u)
(2.7)
18
2.7
B0
B1
B2
C0
C1
D0
The math behind this scheme is obvious if we have the geometrical interpretation (see figure 2.7) Another common representation is to define a recurrence relation for the de Casteljau algorithm. This also yields a triangular
scheme, but we express it as an equation.
19
2.8
2.8.1
(2.8)
Real-time aspects
Computation
The Bezier curve is very cheap to evaluate even with a very small u2 . The
u need not be uniform, but can be increased on flat intervals with criteria
from the control polygon.
The most common way to enhance a surface is to render it with different
types of illumination or even ray-tracing, and these operations require a lot
of processing time compared to the actual evaluation of surface coordinates
and polygon tessellation. This huge topic is covered in many other reports
and books [3][4], and does not get much room in this report.
2
20
2.8.2
Sculpting
A decent editor for Bezier curves and surfaces should allow options of degree and weight together with automatic C 1 continuous concatenation when
adding new segments. In the case of surfaces we also need facilities for intuitive rotation and, as already mentioned, options for different types of
tessellation, shading and other visual attributes.
In some modes of the thesis application, only the control polygon is
drawn in real-time while manipulating the control points, since it requires
too much computation to update the rendered surface continuously. This
provides a rough sketch of the resulting object which is rendered once the
updating stops. Another way to reduce the workload is to only render the
object in its mesh form3 .
One can argue that a slow rendering frequency does not affect the actual
curve or surface, which in fact it does not, but that is a topic of discussion
elsewhere.
Another interesting aspect is that the computer screen is two-dimensional
which complicates the editing of surfaces (or three-dimensional curves). We
first have to project the curve or surface to screen space (two-dimensional),
where we manipulate the control points with the mouse. Once done, we
project the control points back to computation space (three-dimensional).
Of course, the surface can be rotated and hence manipulated implicitly
in three dimensions, but this still poses a problem since it is very hard to
determine the depth value without good visual depth cues4 .
2.9
Summary
To sum up this chapter, here are a few key properties of the Bezier curve
that are good to remember in the chapters to come.
3
4
Polynomial curve
Evaluation by Bernstein polynomials, de Casteljau
Number of control points and degree are dependent
Convex hull property
Interpolation of first and last control point
Geometric operations on control points apply to the entire curve.
21
22
Chapter 3
3.1
3.2
Knots
Q7
Q4
Q8
Q6
Q9
Q5
Segment
3
4
5
6
7
8
9
Control points
0123
1234
2345
3456
4567
5678
6789
In the table above we can see how the local control property is obtained with
1 2
, 14 , . . . , 13
B-spline curves. The uniform knot vector for this curve is [0, 14
14 , 1].
The reason why the segment numbering begins at 3 will become clear once
we look at the basis functions and their evaluation in the next section.
By changing the values of the knot vector we make parametric segments
shorter or longer, and this is one of the biggest advantages of the B-spline
curve (see figure 3.2).
The easiest way to demonstrate this technique is to clamp the end4 5
10
points by changing the knot vector to [0, 0, 0, 0, 14
, 14 , . . . , 14
, 1, 1, 1, 1]. This
transforms the first and last segments to single points which forces the curve
to interpolate the endpoints (figure 3.3)
3.3
When constructing a uniform B-spline curve the basis functions are translates of each other, yielding a very simple basis function. To complicate
things we have to consider the non-uniform case, where the knot values are
not equally distant from one another and this is not a very simple task.
Below we find the Cox de Boor algorithm, which can recursively compute the basis functions to any uniform or non-uniform B-spline curve of
degree n. The knot values with corresponding index is denoted ti and i is
the control point to evaluate.
Bi,1 (t) = 1.0 if ti t ti+1 , else 0.0
ti+2 t
ti+2 ti+1 Bi+1,1 (t)
Bi,2 (t) =
tti
ti+1 ti Bi,1 (t)
Bi,n (t) =
tti
ti+n1 ti Bi,n1 (t)
ti+n t
ti+n ti+1 Bi+1,n1 (t)
greater multiplicity on some knot elsewhere, the graph will peak there.
3.4
B-spline formulation
There are a couple of different ways to describe a B-spline curve. In its most
basic form it looks just like the Bezier formulation.
W m (u) =
n
X
Pi Bi,m (u)
(3.1)
i=0
where P is the control point vector, B the basis function, n the number
of control points and m the degree of the curve. Equation 3.1 is simple to
understand, and uses the fact the B will automatically return 0 if the control
point being evaluated is out of reach of u.
This is however not very efficient since we for every u must evaluate the
basis function for every Pi . In the cubic case we only need to know m+1 = 4
relevant control points since an arbitrary point u is never affected by more
than so many. This topic will be expanded on in coming sections of the
report.
3.4.1
NURBS
The term NURBS stands for Non-Uniform Rational B-Spline and is the
most common way to model curves and surfaces in computer graphics [5],
hence it deserves a topic by itself in this report.
Just as with Bezier curves, a rational curve means that we extend the
control points by one coordinate that will represent the weight, or attraction/repellation, of that particular control point. In figure 3.5 we see a
NURBS curve where all control points are assigned weight 1.0, which is the
default weight-less value.
This can be seen by inspection of the NURBS formulation (equation 3.2)
as wi = 1.0 does not modify any calculations or results.
(3.2)
The curve should lie within the area enclosed by all control points
29
3.5
NURBS surfaces
W (u, v) =
Pt
j=0 wi Pi Bi,m (u)Bj,m (v)
i=0
Pn Pt
i=0
j=0 wi Bi,m (u)Bj,m (v)
Pn
(3.3)
The surface does not have to be of equal degree in both directions, but
to keep things more understandable we settle for this now. Observe the
surface in its rendered form in figure 3.7 where we clearly see the local
control property.
By evaluating this equation we obtain a surface with local control, one
knot vector in each parametric direction and with rational properties; virtually anything one could wish for when modeling a surface.
It goes without saying that Bi,m (u) uses the knot vector u and Bj,m (v)
the knot vector v.
3.6
For the B-spline curve we also have a geometrical way to display the calculations, which is an extension of the de Casteljau algorithm covered in the
previous chapter for Bezier curves. It is called the de Boor algorithm, and
should not be confused with the Cox de Boor algorithm described earlier.
The only difference is that we for a point u must determine which m + 1
control points that affect it, and there after apply the de Casteljau algorithm
to that segment. See figure 2.7 for the geometrical interpretation.
This is not a hard operation since we have a co-relation between the knot
and control point vectors.
In figure 3.8 we see how the de Boor algorithm would evaluate u = 0.4.
Assume we have a knot vector [0, 0, 0, 0, 0.25, 0.5, 0.75, 1, 1, 1, 1] and seven
control points. In the figure we see the control polygon of these.
The point u = 0.4 lies in [0.25, 0.5] and hence the control points affected
are P 1, P 2, P 3, P 4. We remind ourselves that the curve formed by these
points is a Bezier segment and apply the de Casteljau algorithm to calculate
the point.
30
3.7
3.7.1
(3.4)
Real-time aspects
Computation
31
In section 3.4 we briefly discussed the fact that each segment only requires input from m + 1 control points, four in the case of a cubic curve. By
evaluating the curve through segments we can avoid to include every control
point in the calculations.
Say we have knot vector t and wish to evaluate a cubic B-spline with
a control point vector P . We denote the basis function B with arguments
degree, control point and parameter value, in that order.
for i:=3 to sizeof(P):
for u:=t[i] to t[i+1]:
result := 0
result += P[i-3] *
result += P[i-2] *
result += P[i-1] *
result += P[i-0] *
plot result
end for
end for
B(3,i-3,u)
B(3,i-2,u)
B(3,i-1,u)
B(3,i-0,u)
3.7.2
Sculpting
Most properties from Bezier sculpting carry over to the B-spline. The new
thing that we have to consider is the editing of the knot vector(s).
If the GUI (Graphical User Interface) supports input of vectors or strings,
it is quite common to display an editable strip of text where the knot values
can be edited with the keyboard.
A more refined method is to project the knot values to a line or plane
that lies below the curve or surface, where the user can manipulate the
values by dragging the projected icons in the fixed parametric directions,
which is perhaps the most intuitive way to modify the knot vectors.
Knot multiplicity is also a detail to consider, as the software must allow
insertions of several knots at the same coordinate
32
3.8
uui
ui+p ui
for k p + 1 i k
which indeed is a very simple and fast calculation. Notice the similarities to the de Casteljau and de Boor algorithms. Geometrically speaking, the control polygon is unaffected over the entire curve except between
Pk , Pk1 , . . . , Pkp . This method naturally works for inserting knots at existing values with any multiplicity, but this is more efficiently done with the
Oslo algorithm [6] which can insert several knots in one operation.
The reverse operation, the deletion of a knot, requires deletion of a control point and hence it does not preserve the shape of the curve. See [7] for
further reading.
In figure 3.9 we see how the exact same curve can be represented by a
different amount of control points. Here we have inserted a knot at u = 0.8,
on the right half of the curve. This will provide us with greater local control,
and can be repeated if necessary.
3.9
Concatenation
There are algorithms for merging both B-spline curves and patches. The
simplest way to a accomplish a concatenation is to simply create a new
larger curve or patch which contain all the control points, but since we in
most cases work with clamped end points we can apply the same technique
as shown for Bezier curves in the previous chapter. That is, to introduce
a continuity constraint between the last and first couple of points on each
curve.
3.10
So far we have covered a few of the most common types of curves and
surfaces. In this section we look at some other useful types that aid us in
common computer graphics tasks.
34
3.10.1
Natural spline
A natural spline is the real-life model of the spline curves used in computer
graphics. They are strips of flexible metal (aluminum, for instance) that are
C 2 continuous, but they do not posses local control. Moving one control
point affects the entire curve.
3.10.2
Hermite curves
The Hermite curve, named after Charles Hermite, is similar to the Bezier
curve where we specify two endpoints and two other points to determine
the tangents and these endpoints. However, it uses a different set of basis
functions and behaves differently, see figure 3.10. It also interpolates all of
its control points, but does not have a convex hull property.
Influence
3.10.3
Catmull-Rom splines
The Catmull-Rom splines [12], also called Overhauser splines [13], is a set
of splines that interpolate all or most of their control points, hence this
is a very common type of parametric curve that we use to model exact
representations.
The downside to this type of parametric curve is that it does not posses
the convex hull property, which complicates some applications (collision detection, for instance).
35
3.10.4
This type of curve works like a B-spline curve but with two new variables in
the calculations called bias and tension. In addition to the rational extension, we now have two further weights to modify our curve which provide
a higher degree of flexibility. It should be noted that these two parameters
are not exclusive to each control points, but are defined globally. The curve
was presented by Barsky and Bartel [10][11].
The only problem with this spline is that it is only C 0 continuous at
the segment join points (knots). This complicates some of the applications
involving movement discussed in the next chapter. As with the CatmullRom spline, the -spline does not have a convex hull property, neither does
it have local control.
3.11
B-spline summary
Presented below are a few key terms to remember regarding B-spline curves
and their use.
Local control
No relation between degree and number of control points
Knot insertion and the knot vector
Uniformity and non-uniformity
de Boor algorithm
Cox de Boor algorithm
NURBS
36
Chapter 4
Applications
The need for curves and surfaces is very obvious, and here we will cover at
least some areas of application where they are used extensively.
4.1
Camera movement
4.2
Topologies
38
not hard to realize why the NURBS curve have become so popular in game
design over the last couple of decades.
Speaking of surface fitting, this is also a much used model for creating
virtual versions of real characters. We scan the topology of the human face
and adapt the results as control points in a NURBS surface, but often this
needs tweaking since the surface does not interpolate all of its control
points.
4.3
Character movement
4.4
Collision detection
The basic problem behind the topic collision detection is to determine when
objects collide, with as little processing power as possible, while maintaining
a solid behavior.
This is a huge topic by itself and we will concentrate on the advantages
of using parametric representations for curves and surfaces and how to use
them in an interactive application.
To start things off, we have a couple of primitives that are used extensively in collision detection. These consist of planes, spheres, lines and so
forth. The idea is to encapsulate or compose an object with these primitives
2
39
inspected by the user, say a piece of paper with clues in an adventure game.
In the latter case we usually want to make the volumes such that grouped
polygons lie approximately in the same plane or box, so that we can use
documented intersection algorithms that solve very quickly.
One should observe the discussion in earlier topics about using adaptive subdivision, but now applied to the low-resolution surface. By using
this technique wisely and checking for flatness criteria we can save tremendous amounts of processing power for other important tasks. Since half of
the game developers work consists of clever tricks and cheats for greater
performance, we often trade a little bit of accuracy for fewer collision computations, in a case like this.
This tree-structure technique is of course also applicable to curves where
we create bounding boxes to snare smaller and smaller parts of the curve.
4.5
Soft objects
4.6
Automatic LOD
4.7
Object modeling
One last topic that should be mentioned is the ability to create in-game
objects, which is a very common application. This is often done in 3D
modeling software but can be done within the executing applications as
well.
Consider the look of a curved door passage in an ordinary computer
game. There is a large possibility that the frame of this door is done by a Ushaped spline that is tessellated with a certain thickness and then textured.
Another great example are vines, which must be the most suited thing
to model with a spline or Bezier curve, since they by definition respond very
similar to their real aliases.
43
44
Chapter 5
Implementation
This chapter will deal with topics that emerged while developing the thesis
application and some interesting areas of research that are connected to the
actual implementation.
5.1
Simple evaluation
5.2
Forward difference
Most computer scientists and mathematicians have encountered the evaluation method forward difference, which is one way to adapt u according to
some given criteria, in this case flatness of the curve.
The forward difference f (t) of the function f (t) is given by
f (t) = f (t + ) f (t)
(5.1)
fn+1 = fn + fn
(5.2)
where f is evaluated a uniform interval with size . For a cubic polynomial, which is the most common degree for parametric curves and surfaces,
we have
f (t) = at3 + bt2 + ct + d
so the forward difference becomes
45
(5.3)
(5.4)
To further ease the computation we can now apply the same technique
to f (t). Equation 5.2 and 5.4 now gives us
2 f (t) = f (t + ) f (t)
(5.5)
2 f (t) = 6a 2 t + 6a 3 + sb 2
(5.6)
2 fn = fn+1 fn
(5.7)
fn = fn1 + 2 fn1
(5.8)
This yields
or similarly
Since we in this example are working with cubic polynomials the last
and third forward difference will be a constant, and we calculate it just as
shown above. In summary we know have
fn+1 = fn + fn
fn = fn n 1 + 2 fn1
2 fn1 = 2 fn2 + 6a 3
This may seem a bit much just for calculating a line segment, but we
have now reduced the calculations per 3D point from ten additions and
nine multiplications to just nine additions, if we use the Bezier curve as an
example. Though, we have to calculate the initial conditions when using
forward difference, but this only has to be done once.
5.3
Recursive subdivision
5.4
Look-up tables
Look-up tables are often used when we know the evaluation resolution of a
function. In games we most often create them for trigonometric functions,
but we can use them for parametric curves and surfaces as well. For each
control point, we build a table that holds indices to the basis function return
value at each interval. When we show or manipulate the surface in real-time,
we never have to access the cumbersome weighting functions.
As the tables can be come quite large, the trade-off associated with
this trick is storage size. Usually, processor time is of more value than the
memory usage, so it is very common that we implement this feature.
5.5
Portability
47
5.6
Implementation comparison
In this section we shall look at a few comparisons between different implementations and how well they scale. The test involves the calculation of
a typical curve with different resolutions, and the time is measured with a
system profiling tool.
It should be noted that the tests use a system-wide clock, which is not
devoted to one process only. The values are averages of three separate
sessions.
Following each chart is a short text that discusses the differences obtained and why they occurred.
48
Simple
Fw. diff
Seconds
10
12
14
Resolution x 1000
16
18
20
49
Bernstein
de Casteljau
22
20
18
Seconds
16
14
12
10
8
6
4
10
15
20
25
30
Resolution x 1000
35
40
45
50
50
de Boor
Cox de Boor
30
Seconds
25
20
15
10
10
20
30
40
50
60
Resolution x 100
70
80
90
100
51
Bernstein
de Boor
10
Seconds
10
20
30
40
Resolution x 100
50
60
70
52
Chapter 6
Closing remarks
This thesis was intended to be a solid material for beginners in the field
of parametric curves, offering a simple and intuitive sculpting tool and a
walk-through of the theory behind them.
Only a fraction of the applications have been covered here, mostly aspects applicable to computer games and multimedia. The CAD section
would be a thesis of its own, with volumetric sweeps, constructive solid geometry and so forth. Hopefully the reader has gained some understanding
and interest to explore this popular field in computer graphics.
6.1
Personal comments
During earlier experiences with parametric curves, terms like NURBS and
rational curves were intimidating, not least on the mathematical side. Many
students feel the same way, so my effort has been to explain the common
concepts in the easiest way possible. Hopefully this is something that computer graphics classes can take advantage of and hand this material to their
students.
Since mathematics has never been my strong side, it was a good exercise to implement the software and hopefully provide a good explanation for
other students. Some of the implementation may not be entirely correct, but
at least the sculpting software works like intended and will serve as excellent
hands-on experience with the curves and surfaces.
Fun
Fast
File I/O
Intuitive
Portable code
These were the goals of the software, and I feel quite satisfied with the re53
sults. Of course, software like this can be expanded on forever and upgraded
with new functionality.
6.2
Future work
Since surface subdivision is a huge topic and a good alternative for creating polygon meshes and solid objects, this is also a high priority if the
software is continued.
The choice of GUI can also be discussed, since the GLUI package is
rather basic. For instance, it would be convenient to have sliders in the
parametric direction(s) for the knot insertion. This is a very common way
to modify the knot vector, and would be easier to implement if another GUI
package was used (GTK or Qt, for instance).
Regular shading or flat shading implies that we specify one normal per
polygon. This means that the polygon will be rendered with equal intensity
across its span, hence it requires a large amount of polygons to get a smooth
appearance.
There are two major techniques to create interpolated shading, Phongand Gourad shading. In the case of Phong, the polygon is illuminated pixelper-pixel by interpolating the vertex normals. In its basic form it is very
slow and not suitable for real-time. There are some clever versions which
approximate the Phong model, and these are also considered to be of high
priority since they enhance the visual experience tremendously.
In Gourad shading, we instead interpolate the color of each vertex across
the polygon. This also yields a very pleasing result, but as with Phong
shading it requires some clever tricks while rendering the parametric surface.
We need to have some kind of list at each vertex that holds pointers to the
surrounding polygons or vertices, and this is not very trivial if it is to be
done in real-time.
6.3
The thesis software has been developed on Linux Mandrake 9.1 with OpenGL
1.4, Glut 3.7 and GLUI 2.1. It should compile on any platform which sup54
55
56
References
1. Bernstein, S. Dmonstration du thorme de Weierstrass fonde sur le calcul
des probabilities. Comm. Soc. Math. Kharkov 13, 1-2, 1912.
2. Lorents, G. Bernstein polynomials. Toronto Press, 1953.
3. Foley, J D. van Dam, A. Feiner S K. Hughes J F. Computer Graphics
principles and practice. Addison/Wesley, 1997.
4. Watt, A. Policarpo, F. 3D games Real-time rendering and Software
technology, Addison/Wesley, 2001.
5. Farin, G E. NURBS from Projective Geometry to Practical Use. A K
Peters, 1999.
6. Lyche, T., K. Moerken and K. Stroem,Conversion between B-spline bases,
in Knot Insertion and Deletion Algorithms for B-spline Curves and Surfaces, R. N. Goldman and T. Lyche (eds.), SIAM, Phil, 1993, 135153.
7. Lyche, T., Knot removal for spline curves and surfaces, in Approximation Theory VII, E. W. Cheney, C. K. Chui, and L. L. Schumaker, (eds.),
Academic Press, Boston, 1993, 207227.
8. de Casteljau, F. Outillage Methodes Calcul, Anre Citroen Automobiles
SA, Paris 1959.
9. Bezier, P. Emploi des Machines a Commande Numerique, Masson et
Cie, Paris 1970.
10. Barsky, B. Computer Graphics and Geometric Modeling Using Betasplines, Springer-verlag, New York 1988.
11. Bartels, R., J. Beatty, and B.Barsky, An introduction to Splines for
Use in Computer Graphics and Geometric Modeling, Morgan Kaufmann,
Los Altos, CA, 1987.
12. Catmull, E., and R.Rom. A Class of Local Interpolating Splines in
Barnhill. R., and R. Riesenfeld, eds., Computer Aided Geometric Design,
Academic Press, San Francisco, 1974, 317-326.
13. Brewer, H., and D. Andersson, Visual Interaction with Overhauser
Curves and Surfaces, SIGGRAPH 77, 132-137.
57
58