Graphics Handout 05
Graphics Handout 05
Parametric Splines
We can improve our choice by the simple expedient of using a parametric spline. Let us consider first a quadratic
polynomial spline written in vector notation as:
P = a2 µ 2 + a1 µ + a0 (1)
where a0 , a1 and a2 are constant vectors whose values determine the shape of the spline. For two dimensional
curves we now therefore have six unknowns (rather than the three previously). We can use these extra degrees
of freedom to control the shape of the curve.
(d)
We will use the convention that 0 ≤ µ ≤ 1 over the range of interest. Hence at µ = 0 the curve is at the
first point to be interpolated, and at µ = 1 it is at the last. Now consider interpolating the three points as before
(P0 = [x0 , y0 ], P1 = [x1 , y1 ] and P2 = [x2 , y2 ]). When µ = 0 the curve passes through the first point, say
P2 = a2 + a1 + a0 ,
SplinePatches
Although we have gained more freedom by using
the parametric form, we do not have any intuitive
way of using it. That is to say, we have no simple
way to choose µ values for each point to get the
type of interpolating spline we want. Moreover,
we still face the problem of having to use ever
higher degrees of polynomials for higher numbers
of points. To overcome these difficulties we intro- Figure 3: A simple way to join patches
duce a method based on spline patches that allows
simple intuitive spline construction. We define a
different curve between each pair of adjacent knots, as shown in Figure 3. This is most commonly done by
using a cubic spline for each patch, rather than the quadratic splines formulated above. The reason for choosing
a cubic form is so that we can join the patches smoothly together. The equation for a parmetric cubic spline
patch has four unknowns, a0 , a1 , a2 and a3 :
P = a3 µ3 + a2 µ2 + a1 µ + a0 (4)
We use the extra degrees of freedom provided by the cubic equation to set the gradient at either end of the patch,
and thus make it join seamlessly to its neighbours. Looking at Figure 3, we see that this can conveniently be
done by taking the difference of the coordinates on either side of the knot in question. This however is not the
only way of setting this gradient, as we will see later. If we differentiate the curve equation we get:
Now consider the two ends of a spline patch between Pi and Pi+1 , where µ = 0 or µ = 1. We can find
the positions and gradients at each end by substituting µ = 0 and µ = 1 into equations 4 and 5 which gives:
Pi = a0
P0i = a1
Pi+1 = a3 + a2 + a1 + a0
P0i+1 = 3a3 + 2a2 + a1
We can write this system of equations in matrix form:
1 0 0 0 a0 Pi
0 1 0 0 a 1 P0
i
1 1 1 1 a2 = Pi+1 (6)
0 1 2 3 a3 P0i+1
Notice that we have vector quantities, so, this formulation represents eight equations for the 2D case, and twelve
for the 3D case. The matrix is the same for each dimension. For any given set of knots, this cubic patch method
gives a stable, practical solution.
Bezier Curves
One of the simplest ways of approximating a curve was made
popular by the French mathematician Pierre Bezier in the con-
text of car body design. It was based on a mathematical formu-
lation by another French mathematician Paul de Casteljau. A
typical Bezier curve is shown in Figure 4. Here four knots P0 ,
P1 , P2 , P3 are shown. The gradient at each end of the Bezier
curve is the same as the gradient of the line joining the first two
knots, thus: P00 = k(P1 −P0 ), where k is the number of knots
- 1. This is an important property as it allows us to join Bezier
patches together smoothly. Computation of the Bezier Curve
Figure 4: A typical Bezier Curve
may be done in two ways. The first uses a recursive algorithm
based on a method of Casteljau. The idea is illustrated by Fig-
ure 5. For a given value of µ, say 1/2 we first construct the points on the lines [P0,0 , P0,1 ] [P0,1 , P0,2 ] and
[P0,2 , P0,3 ] for the chosen value of µ. These are labelled as the first set of constructed points, P1,0 , P1,1 and
P1,2 . The new points are joined up and the same procedure is followed to construct the second set of points
P2,0 and P2,1 . The process is repeated to find the point P3,0 . This is a point on the Bezier curve. As µ varies
from 0 to 1 the locus of P3,0 traces out the Bezier Curve. Using a functional pseudocode which allows us such
liberties as scalar and vector multiplications and typed functions, this algorithm can be written very simply:
Point Casteljau (knots P[] ; int N, int r, float µ)
begin
if (r == 1)
then Casteljau = µ*P[N+1] + (1-µ)*P[N]
else Casteljau = µ*Casteljau(P,N+1,r-1,µ) + (1-µ)*Casteljau(P,N,r-1,µ)
end
and the curve can be drawn with:
for j=1 to L
begin
locus=Casteljau(Knotarray,0,N,j/L)
drawto(locus.x,locus.y)
end
Note that here, and for all subsequent treatment of splines we will use a set of N+1 knots, labelled 0 to N.
Blending
Another way to view a Bezier curve is to think of it as a blend of its knots. In the simplest case, if we apply the
Casteljau algorithm to the degenerate case of two knots we get the parametric line equation:
P = µP0,1 + (1 − µ)P0,0
P(µ) = a3 µ3 + a2 µ2 + a1 µ + a0
where a3 = P3 − 3P2 + 3P1 − P0
a2 = 3P2 − 6P1 + 3P0
a1 = 3P1 − 3P0
a0 = P0
we differentiate to get:
P0 (µ) = −3P0 (1 − µ)2 + 3P1 (1 − µ)2 − 6P1 µ(1 − µ) + 6P2 µ(1 − µ) − 3P2 µ2 + 3P3 µ2
P0 (µ) = (3P1 − 3P0 )(1 − µ)2 + (6P2 − 6P1 )µ(1 − µ) + (3P3 − 3P2 )µ2
So at the start, where µ = 0, the gradient is 3P1 − 3P0 and at the end, where µ = 1, the gradient is 3P3 − 3P2 .
This confirms that the curve is tangential to P1 − P0 at the start and P3 − P2 at the end.
d g i 1 1
which multiplies out to:
ax2 + ey 2 + hz 2 + 2bxy + 2cxz + 2f yz + 2dx + 2gy + 2iz + 1 = 0
and the nine scalar unknowns (a, b, ..i) can be found by specifying nine points Pi = [xi , yi , zi ] through which
the surface must pass. This creates a system of nine linear equations to solve. Notice that because of the
inherent symmetry of the formulation there are only nine unknowns, not sixteen. The constant term can always
be taken as 1 without loss of generality. This method however suffers the same limitations as the analogous
method for curves. It is difficult to control the surface shape since there is only one quadratic surface that will
fit the points.
Parametric Surfaces
It is a simple generalisation to go to parametric surfaces. In the case of spline curves, the locus of a point was a
function of one parameter. However a point on a surface patch is a function of two parameters, which we write
as P(µ, ν). We could define a parametric surface using a matrix formulation:
a b c µ
P(µ, ν) = [µ, ν, 1] b d e ν = 0
c e f 1
Multiplying out we get:
P(µ, ν) = aµ2 + 2bµν + 2cµ + dν 2 + 2eν + f (1)
The values of the constant vectors (a,b, . . f) determine the shape of the surface. The surface has edges given
by the four curves for which one of the parameters is either 0 or 1. These are the quadratics:
P(0, ν) = dν 2 + 2eν + f
P(1, ν) = a + 2(b + e)ν + 2c + dν 2 + f
P(µ, 0) = aµ2 + 2cµ + f
P(µ, 1) = aµ2 + 2(b + c)µ + d + 2e + f
The unknown values in the matrix (a, b, c etc) are
all vectors whose values can be computed by sub-
stituting in six points to be interpolated for given
values of µ and ν. Just as we did for the spline
curves, we need to specify the values of µ and
ν where the knots are located. For example, one
possibility is:
µ ν
P0 0 0
P1 0 1
P2 1 0
P3 1 1
P4 1/2 0 Figure 1: A simple Quadratic Surface
P5 1/2 1
y = f (x, z)
A typical patch is shown in figure 2. At every grid Figure 2: A “Terrain” Surface Patch
point there are two gradients which we can write
∂y
as ∂x and ∂y
∂z . Thus, if we are going to fit a patch to the four points, we need twelve parameters in the equation
of the patch, so that we can match the positions and both gradients at the four corners. Furthermore, we need
to ensure continuity along the boundaries of the patches. Rather than try to develop one equation which will do
this for us, we normally use bi-cubic interpolation. It will be seen from figure 2 that we can easily design spline
curves for the four edges. These curves will be continuous with the neighbouring patches. Thus we adopt a
solution where we use these curves at the edges of the patch, and we interpolate them in the middle of the patch.
P(µ, ν) = P(µ, 0)(1 − ν) + P(µ, 1)ν + P(0, ν)(1 − µ) + P(1, ν)µ − P(0, 0)(1 − µ)(1 − ν)
−P(0, 0)(1 − µ)ν − P(0, 0)µ(1 − ν) − P(1, 1)µν (2)
This is a tricky equation to understand, but you can verify that you get the four edge contours by substituting
µ=0, µ=1, ν=0 and ν=1. The first four terms are simply a linear interpolation of both the bounding curves.
However it is clear that we cannot just add them together, as this would no longer go through the four points
that define the patch. The last four negative terms correct the curve at the corner points without introducing any
discontinuity. This formulation is called the Coon’s Patch, and is probably the easiest to use surface construction
method.
P(µ, 0) = a3 µ3 + a2 µ2 + a1 µ + a0
We need to solve for the four constant vectors a3 , a2 , a1 and a0 , and we do this using the matrix formulation
introduced in the lecture on spline curves which yields:
a0 = P0 = (9, 4, 12)
a1 = P00 = (1, 0, 1.5)
a2 = −3P0 − 2P00 − 3P1 − P01 = −3 ∗ (9, 4, 12) − 2 ∗ (1, 0, 1.5) + 3 ∗ (10, 4, 13) − (1, 0, 1) = (0, 0, 1)
a3 = 2P0 + P00 − 2P1 + P01 = 2 ∗ (9, 4, 12) + (1, 0, 1.5) − 2 ∗ (10, 4, 13) + (1, 0, 1) = (0, 0, 0.5)
Similarly we can solve for the other bounding curves P(µ, 1), P(0, ν) and P(1, ν).
We now have equations for all the individual terms in the Coon’s patch:
P(µ, 0): a cubic polynomial in µ
P(µ, 1): a cubic polynomial in µ
P(0, ν): a cubic polynomial in ν
P(1, ν): a cubic polynomial in ν
P(0, 0), P(0, 1), P(1, 0) and P(1, 1): the corner points,
so given µ and ν we can evaluate each of these eight terms and so find the coordinate on the Coon’s patch using
equation 2.
Suppose that the following function is used to transform texture coordinates (α, β ) into an
intensity value:
(α + β )
I= I max
2
I is therefore the intensity given to a pixel which corresponds to position (α, β ) in texture space.
A quadrilateral is projected onto the screen. The screen coordinates and texture coordinates of its
vertices are as follows:
1. Let Pt be the point with screen coordinates (30, 30). Calculate the texture coordinates (α, β)
corresponding to Pt and find the intensity to be applied to Pt.
N.B. Use bi-linear interpolation to find the texture coordinates, i.e. solve for (α, β ) the equation:
p = αβ (c − b) + α a + β b
Where
p = Pt - P1 a = P4 - P1 b = P2 - P1 c = P3 - P4
For example, consider the line from P1 to P2: At P1 β = 0 and at P2 β = 1 and there are 26 pixels on
the line (the biggest change in the screen coordinates is along the y-component, from 5 to 30,
which gives 26 pixels including the end-points).
Moving along the line from P1 to P2, the differential change in β from one pixel to the next is
1 because 26 pixels (including end-points) have 25 spaces between them.
25
Thus, we can estimate the values of β at each pixel along the line simply by adding the differential
as we move from one pixel to its neighbour.
2. What are the differentials in α and β for the four lines bounding the quadrilateral?
3. Now consider the horizontal line through the point (30, 30). Using the differential method
above, find the values of α and β at the points where it intersects the sides of the quadrilateral, and
hence find the differentials in α and β along the line.
4. Use these differential values to compute α and β at the point (30, 30). Find also the
corresponding intensity to be given to the pixel. Compare your results with the values obtained in
part 1.
5. Can you suggest why the methods in parts 1 and 3 do not give exactly the same result?
Notice that with the differential method, calculating α and β for most of the pixels in the
quadrilateral requires only two additions, and hence is much faster.