advanced graphics lecture five
DESCRIPTION
Advanced Graphics Lecture Five. Revenge of the NURBS. Alex Benton, University of Cambridge – [email protected] Supported in part by Google UK, Ltd. History. - PowerPoint PPT PresentationTRANSCRIPT
Advanced GraphicsLecture Five
Revenge of the NURBS
Alex Benton, University of Cambridge – [email protected]
Supported in part by Google UK, Ltd
History
The term ‘spline’ comes from the shipbuilding industry: long, thin strips of wood or metal would be bent and held in place by heavy ‘ducks’, lead weights which acted as control points of the curve.
Wooden splines can be described by Cn-continuous Hermite polynomials which interpolate n+1 control points. Top: Fig 3, P.7, Bray and Spectre, Planking and Fastening, WoodenBoat Pub (1996)
Bottom: http://www.pranos.com/boatsofwood/lofting%20ducks/lofting_ducks.htm
History
Curves which must have n+1 control points are hard to work with. (n+1)x(m+1) patches are even moreso.
But continuity—smooth curves—is essential to the perception of quality of manufacture. Especially in cars, and some Apple products.
Splines were generalized in the 1960s by Bezier (Renault), de Casteljau (Citroen), de Boor (GM).
Beziers—a quick review
A Bezier cubic is a function P(t) defined by four control points:• P0 and P3 are the endpoints of the
curve; P1 and P2 define the other two corners of the bounding trapezoid.
• The curve fits entirely within the bounding trapezoid.
P0
P1 P2
P3
Joining Bezier splines
To join two Bezier splines with C0 continuity, set P3=Q0.
To join two Bezier splines with C1 continuity, require C0 and make the tangent vectors equal: set P3=Q0 and P3-P2=Q1-Q0.
P3Q0
Q1
P2
Joining Bezier patches
This works for Bezier patches as well: to join two patches with C1 continuity at an edge, ensure that their control points and tangent vectors on that edge are equal.
NURBS patches arejoined in exactly thesame way.
Beziers
Cubics, of course, are just one example of Bezier splines:
Linear: P(t) = (1-t)P0 + tP1
Quadratic: P(t) = (1-t)2P0 + 2t(1-t)P1 + t2P2
Cubic: P(t) = (1-t)3P0 + 3t(1-t)2P1 + 3t2(1-t)P2 + t3P3
...
General: 10,)1()(0
tPtt
i
ntP i
iinn
i
“n choose v” = n! / i!(n-i)!
Beziers
Thinking about Beziers• Linear interpolations
• The linear Bezier is a linear interpolation between two points.
• The quadratic Bezier can be seen as a linear interpolation between two lines:
P(t) = (1-t) ((1-t)P0+tP1) + (t) ((1-t)P1+tP2)
• The cubic is a linear interpolation between linear interpolations between linear interpolations… etc.
• Another way to see Beziers is as a weighted average between the control points.
P0
P1
P2(1-t)P0+tP1
(1-t)P1+tP2
P(t)
Bernstein polynomials
P(t) = (1-t)3P0 + 3t(1-t)2P1 + 3t2(1-t)P2 + t3P3
The four control functions are the four Bernstein polynomials for n=3.• General form:
• Bernstein polynomials in 0 ≤ t ≤ 1 always sum to 1:
0.2 0.4 0.6 0.8 1
0.2
0.4
0.6
0.8
1
0.2 0.4 0.6 0.8 1
0.1
0.2
0.3
0.4
0.2 0.4 0.6 0.8 1
0.1
0.2
0.3
0.4
0.2 0.4 0.6 0.8 1
0.2
0.4
0.6
0.8
1
vnvnv tt
v
ntb
)1()(,
1))1(()1(0
nn
v
vnv ttttv
n
Parameterizing a chain of Beziers We can parameterize this chain
over t by saying that instead of going from 0 to 1, t moves smoothly through the intervals [0,1,2,3]
The curve C(t) would be: C(t) = P(t) • ((0 ≤ t <1) ? 1 : 0) +
Q(t-1) • ((1 ≤ t <2) ? 1 : 0) +R(t-2) • ((2 ≤ t <3) ? 1 : 0)
[0,1,2,3] is, in a way, a type of knot vector. 0, 1, 2, and 3 are the knots.• This is not strictly true, but the
idea is right: knots define intervals.
Consider a chain of splines with many control points…• P = {P0, P1, P2, P3}• Q = {Q0, Q1, Q2, Q3}• R = {R0, R1, R2, R3}
…with C1 continuity…• P3=Q0, P2-P3=Q0-Q1• Q3=R0, Q2-Q3=R0-R1
P3Q0
Q1
P2
Q3
Q2
R1
R0
NURBS
NURBS (“Non-Uniform Rational B-Splines”) are a generalization of Beziers.• NU: Non-Uniform. The control points don’t have
to be weighted equally.
• R: Rational. The spline may be defined by rational polynomials (homogeneous coordinates.)
• BS: B-Spline. A chained series of Bezier splines with controllable degree.
B-Splines
A Bezier cubic is a polynomial of degree three: it must have four control points per spline, it must begin at the first and end at the fourth, and it assumes that all four control points are equally important.
Beziers are actually a type of B-spline. B-splines are a piecewise parameterization of Beziers that supports an arbitrary number of control points and lets you specify the degree of the polynomial which interpolates them.
B-Splines
We’ll build our definition of a B-spline from:
• n+1, the number of control functions
• k, the degree of the curve
• {P0…Pn}, a list of n+1 control points
• [t0,t1,…,tk+n+1], a knot vector of parameter values n intervals → n+1 control points k is the degree of the curve, so k+1 is the number of control points
which influence a single interval. k must be at least 1 (two control points linked by each linear line segments) and no more than n (the number of intervals.)
There are k+n+2 knots, and ti ≤ ti+1 for all ti.
B-Splines
The equation for a B-spline is
Ni,k(t) is the basis function of control point Pi. Ni,k(t) is defined recursively:
maxmin0
, ,)()( tttPtNtP i
n
iki
)()()(
otherwise,0
,1)(
1,111
11,,
10,
tNtt
tttN
tt
tttN
ttttN
kiiki
kiki
iki
iki
iii
B-Splines
N0,0(t) N1,0(t) N2,0(t) N3,0(t) …
N0,1(t) N1,1(t) N2,1(t)
N0,2(t) N1,2(t)
N0,3(t)
…
…
…
t0 t1 t2 t3 t4 …
B-Splines
5t4 1,(t)N
4t3 1,(t)N3t2 1,(t)N
2t1 1,(t)N1t0 1,(t)N
4,0
3,02,0
1,00,0
Knot vector = {0,1,2,3,4,5}, k = 0
N0,0(t) N1,0(t) N2,0(t) N3,0(t)0 1 1 2 2 3 3 4
otherwise,0
,1)( 1
0,ii
i
ttttN
N3,0(t)54
B-Splines
5t4)5(
4t3)3()(
45
5)(
34
3(t)N
4t3)4(
3t2)2()(
34
4)(
23
2(t)N
3t2)3(
2t1)1()(
23
3)(
12
1(t)N
2t1)2(
1t0)(
12
2)(
01
0(t)N
0,30,23,1
0,30,22,1
0,20,11,1
0,10,00,1
t
ttN
ttN
t
t
ttN
ttN
t
t
ttN
ttN
t
t
ttN
ttN
t
N0,1(t) N1,1(t) N2,1(t)
)()()( 1,111
11,, tN
tt
tttN
tt
tttN ki
iki
kiki
iki
iki
-1 1 2 3 4 5
0.2
0.4
0.6
0.8
1
-1 1 2 3 4 5
0.2
0.4
0.6
0.8
1
-1 1 2 3 4 5
0.2
0.4
0.6
0.8
1
Knot vector = {0,1,2,3,4,5}, k = 1
-1 1 2 3 4 5
0.2
0.4
0.6
0.8
1
N3,1(t)
B-Splines
54)5)(2/)5((
43)3)(2/)5(()4)(2/)2((
32)2)(2/)2((
)(35
5)(
24
2(t)N
43)4)(2/)4((
32)2)(2/)4(()3)(2/)1((
21)1)(2/)1((
)(24
4)(
13
1(t)N
32)3)(2/)3((
21)1)(2/)3(()2)(2/(
10))(2/(
)(13
3)(
02
0(t)N
1,31,21,2
1,21,11,2
1,11,00,2
ttt
ttttt
ttt
tNt
tNt
ttt
ttttt
ttt
tNt
tNt
ttt
ttttt
ttt
tNt
tNt
N0,2(t) N1,2(t)
)()()( 1,111
11,, tN
tt
tttN
tt
tttN ki
iki
kiki
iki
iki
-1 1 2 3 4 5
0.1
0.2
0.3
0.4
0.5
0.6
0.7
-1 1 2 3 4 5
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Knot vector = {0,1,2,3,4,5}, k = 2
-1 1 2 3 4 5
0.1
0.2
0.3
0.4
0.5
0.6
0.7
N2,2(t)
0.5 1 1.5 2 2.5 3
0.5
1
1.5
2
2.5
3
B-Splines
0.5 1 1.5 2 2.5 3
0.5
1
1.5
2
2.5
3
At k=1 the function is piecewiselinear, depends on P0,P1,P2,P3, and is fully defined on [t1,t4).
Each degree-k control function depends on k+1 knot values, so Ni,k depends on ti through ti+k, inclusive. So six knots → five discontinuous functions → four piecewise linear interpolations → three quadratics, interpolating three control points. n+1=3 control points, k=2 degree, n+1+k+1=6 knots.
At k=2 the function is piecewisequadratic, depends on P0,P1,P2, and is fully defined on [t2,t3).
Knot vector = {0,1,2,3,4,5}
Non-Uniform B-Splines
The knot vector {0,1,2,3,4,5} is uniform: ti+1-ti = ti+2-ti+1 ti.
Varying the size of an interval changes the parametric-space distribution of the weights assigned to the control functions.
Repeating a knot value reduces the continuity of the curve in the affected span by one degree.
Repeating a knot k+1 times will lead to a control function being influenced only by that knot value; the spline will pass through the corresponding control point with C0 continuity.
Open vs Closed
A knot vector which repeats its first and last knot values k+1 times is called closed, otherwise open.• Repeating the knots k+1 times is the only way to
force the curve to pass through the first or last control point.
• Without this, the functions N0,k and Nn,k which weight P0 and Pn would still be ‘ramping up’ and not yet equal to one at the first and last ti.
Open vs Closed
Two examples you may recognize:• k=2, n+1=3 control points, knots={0,0,0,1,1,1}
• k=3, n+1=4 control points, knots={0,0,0,0,1,1,1,1}
Non-Uniform Rational B-Splines
Repeating knot values is a clumsy way to control the curve’s proximity to the control point.• We want to be able to slide the curve nearer or
farther without losing continuity or introducing new control points.
• The solution: homogeneous coordinates.
• Associate a ‘weight’ with each control point: ωi.
Non-Uniform Rational B-Splines
Recall: [x, y, z, ω]H → [x / ω, y / ω, z / ω]
• Or: [x, y, z,1] → [xω, yω, zω, ω]H
The control point Pi=(xi, yi, zi)
becomes the homogeneous control point PiH =(xiωi, yiωi, ziωi)
A NURBS in homogeneous coordinates is:maxmin
0, ,)()( tttPtNtP iH
n
ikiH
Non-Uniform Rational B-Splines
To convert from homogeneous coords to normal coordinates:
)(/)()(
)(/)()(
)(/)()(
ttztz
ttyty
ttxtx
H
H
H
n
ikii
n
ikiiiH
n
ikiiiH
n
ikiiiH
tNt
tNztz
tNyty
tNxtx
0,
0,
0,
0,
))()(()(
))()(()(
))()(()(
))()(()(
Non-Uniform Rational B-Splines
A piecewise rational curve is thus defined by:
with supporting rational basis functions:
• This is essentially an average re-weighted by the ω’s. Such a curve can be made to pass arbitrarily far or
near to a control point by changing the corresponding weight.
maxmin0
, ,)()( tttPtRtP i
n
iki
n
jkjj
kiiki
tN
tNtR
0,
,,
)(
)()(
Non-Uniform Rational B-Splines in action
Tensor products for surfaces
The tensor product of two vectors is a matrix.
Can also take the tensor of two polynomials.
cfcecd
bfbebd
afaead
f
e
d
c
b
a
NURBS surfaces The tensor product of the polynomial
coefficients of two NURBS splines is a matrix of polynomial coefficients.• If curve A has degree k and n+1 control
points and curve B has degree j and m+1 control points then A⊗B is an (n+1)x(m+1) matrix of polynomials of degree max(j,k).
• So all you need is (n+1)(m+1) control points and you’ve got a rectangular surface patch!
This approach generalizes to triangles and arbitrary n-gons.
References
Les Piegl and Wayne Tiller, The NURBS Book, Springer (1997)
Alan Watt, 3D Computer Graphics, Addison Wesley (2000)
G. Farin, J. Hoschek, M.-S. Kim, Handbook of Computer Aided Geometric Design, North-Holland (2002)
Really good book!