<<

Cubic Splines A representation of cubic spline consists of: • four control points (why four?) • these are completely user specified EECS 487: Interactive • determine a set of blending functions

Computer Graphics There is no single “best” representation of cubic spline:

Cubic Interpolate? Local? Continuity Affine? Convex*? VD*?

Lecture 37: 1 Hermite C n/a n/a • B-splines Cardinal except C1 no no

• Rational Bézier and NURBS (Catmull-Rom) endpoints Bézier endpoints C1

natural C2 n/a n/a

B-splines C2 * n/a when some of the control “points” are tangents, not points

Natural Cubic Spline Natural Cubic Spline A natural cubic spline’s control points: 1 2 3 Given n control points, a natural cubic f(u) = a0 + u a1 + u a2 + u a3 1 2 3 spline has n−1 segments • position of start point p0 = f(0) = a0 + 0 a1 + 0 a2 + 0 a3 st 1 2 • 1 derivative of start point p1 = f '(0) = a1 + 2 *0 a2 + 3*0 a3 nd 1 2 • 2 derivative of start point p2 = f ''(0) = 2 *1 a2 + 6 *0 a3 For segment i: fi (0) = pi−1, i = 1,…,n 1 2 3 • position of end point p3 = f(1) = a0 + 1 a1 + 1 a2 + 1 a3 fi (1) = pi , i = 1,…,n

• constraint and matrices: ' ' ⎡ 1 0 0 0 ⎤ ⎡ 1 0 0 0 ⎤ fi (0) = fi−1(1), i = 1,…,n −1 ⎢ ⎥ ⎢ ⎥ " " 0 1 0 0 −1 0 1 0 0 C ⎢ ⎥, B C ⎢ ⎥ fi (0) = fi−1(1), i = 1,…,n −1 = = = 0 0 1 0 ⎢ 0 0 2 0 ⎥ ⎢ 2 ⎥ ⎢ 1 1 1 1 ⎥ ⎢ −1 −1 − 1 1 ⎥ ⎣ ⎦ ⎣ 2 ⎦ f "(0) f "(1) 0 • subsequent segments assume the position and 1st and 2nd Set: 1 = n = derivatives of the end point of the preceding segment

O’Brien Natural Cubic Splines B-splines

Each segment (other than the first) receives Given n (≥ d + 1) control points, three out of its four control points from the a B-spline curve has n−d segments 2 preceding segment, this gives the curve C continuity • d is the degree of each B-spline segment

• the segments are numbered d to n−1, for ease of notation However the coefficients are dependent on all n control points • number of control points is independent of the degree • unlike a Bézier spline, where adding a control • control is not local: any change in any segment point necessarily increases degree by one, may change the whole curve • and unlike multi-segmented Bézier curve where multiple control • curve tends to be ill-conditioned: a small change points supporting a new segment must be added at the same time at the beginning can lead to large subsequent changes • segment degree (d) is also curve degree

B-splines of degree d are said to have order k (= d + 1)

TP3, Watt

Advantages of B-splines Local Control Main advantages of B-splines: • number of control points not limited by degree (d) Unlike natural splines and Bézier curves, B-splines’ • automatic Cd1 continuity control points are not derivatives • local control Instead each segment is a weighted-sum of d basis To create a large model with C2 continuity and functions (only), giving the control points local local control, you pretty much want to use cubic control B-splines Hence Basis spline Aside from the first segment, each B-spline segment shares the first d control points with its preceding segment • sounds like natural spline … how can B-splines have local control? as a

2 n Polynomials f (u) = a0 + a1u + a2u + … + anu • can be added: just add the coefficients • can be multiplied by a scalar: multiply the coefficients • are closed under addition and multiplication by scalar • i.e., the result is still a polynomial Why is B called the Basis Matrix? It’s a vector space!

A vector space is defined by a set of basis • linearly independent vectors • linear combination of the basis vectors spans the space • here vector = polynomial

Durand

Canonical Power Basis Basis Matrix and Basis Functions 1, u, u2, u3, … , un A basis matrix (B) transforms the canonical basis (u) • are independent to another basis: • any polynomial is a linear combination of these, n 2 n a0 + a1u + a2u + … + anu f(u) = ua = uBp = (1− u)p0 + up1 = ∑bi (u)pi • often called the canonical basis functions i=0 n Just as with Euclidean space, uB = ∑bi (u) there are infinite number of possible basis i=0

For cubic, the basis functions could be, for example: The bi(u)’s are the basis functions of the other basis • 1, 1+u, 1+u+u2, 1+u–u2+u3 (we’ve known them as the blending functions) • u3, u3–u2, u3+u, u3+1

Durand B-splines Uniform B-splines Given n control points, there are n−d segments The knots of a uniform B-splines are spaced at • we call the segments fi(u), d ≤ i < n • each segment has a unit range, 0 ≤ u ≤1 equal intervals • P we call the entire B-spline curve with n control points f(t) y(t) 9 P 8 a cubic

P P f (u) t f9(u) B-spline The parameters t ’s where two segments join are 1 3 5 P 10 Q9 i Q5 4 P called knots 7 P t y(t) 9 P t 9 8 a cubic 6 f (u) t5 Q8 • the start and end points (td and tn) B-spline 8 P1 P3 t Q t f (u) t f Q(u) P 10 f9(9u) 3 6 8 5 5 4 Q Q6 are also called knots P7 f (u4) t 4 t 9 P t 6 f (u) t4 6 5 Qf8(u) 3 Q t t 8 3 7 Qf7(u) • [t , t ] 3 t8 the range d n is the domain Qf66(u) 7 Q4 t f4(u) P 4 t 6 f3Q(u3) 7 Q of a B-spline curve f77(u) P5 P Knot • the parameter u of segment i is 5 Knot P P0 P Control point 0 P2 Control point 2 scaled to ti ≤ u < ti+1 x(t) x(t) Foley, van Dam90

Foley, van Dam90

What Degree is Sufficient? Linear B-spline Segment

Arbitrary curves have an uncountable number of In the linear case, the basis functions are b0(u) = (1−u) and b1(u) = u parameters 1

Real-number value expanded into an infinite set of basis functions: 0 1 2 ∞ f(u) = b (u)p (a.k.a. tent/triangle basis, the i’th functions are ∑ i i i=0 shifted versions of the 0’th)

Approximate by truncating set ⎧ 0 u < −1 ⎫ ⎪ 1+ u −1 < u < 0 ⎪ at some reasonable point, e.g., 3: b(u) = ⎨ ⎬ 3 ⎪ 1− u 0 < u < 1 ⎪ ⎪ 0 u > 1 ⎪ f(u) = ∑bi (u)pi ⎩ ⎭ i=0 O’Brien James,Hanrahan Linear B-spline Curve Linear B-splines Consider using linear B-splines (d=1, k=2) to draw The influence of control point pi on the whole curve a piecewise linear curve (a polyline) is thus the “tent/triangle” function: pi+1

To draw the curve, we perform linear ⎧ t t pi − i p ⎪ , ti ≤ t < ti+1, i−1 of a set of control points p , …, p t t 0 n–1 ⎪ i+1 − i ⎪ t = i+2 bi(t) b (t) = ti 2 − t t = i–1 fi(u) i ⎨ + 1 , ti+1 ≤ t < ti+2 , t = i+1 t t ti+2 − t pi+1 ⎪ t t − i pi–1 i+2 − i+1 p0 pi–2 pi+2 t − t pn–1 ⎪ ti+1 − ti i+2 i+1 pi 0, everywhere else t = i ⎪ t = i+3 ⎩ ti ti+1 ti+2

For segment i, we write the interpolating linear The hardest part of working with B-splines is t − ti keeping track of the tedious notations! curve as fi(u) = (1−u)pi–1+ upi, where u = ∈[0,1] ti+1 − ti

[Craig] [Craig]

Linear B-splines Linear B-splines

ti+1 − t t − ti t − ti Linearly interpolating the set of control points to draw fi (u) = (1− u)pi−1 + upi = pi−1 + pi , u = , ti ≤ t < ti+1 t − t t − t t − t the curve: i+1 i i+1 i i+1 i ti+2 − t t − ti+1 t − ti+1 t t t t t t fi+1(u) = (1− u)pi + upi+1 = pi + pi+1, u = , ti+1 ≤ t < ti+2 i+1 − − i − i t − t t − t t − t fi (u) = (1− u)pi−1 + upi = pi−1 + pi , u = , ti ≤ t < ti+1 i+2 i+1 i+2 i+1 i+2 i+1 ti+1 − ti ti+1 − ti ti+1 − ti

ti+2 − t t − ti+1 t − ti+1 We can rewrite the segment functions as: fi+1(u) = (1− u)pi + upi+1 = pi + pi+1, u = , ti+1 ≤ t < ti+2 ti+2 − ti+1 ti+2 − ti+1 ti+2 − ti+1 fi (t) = bi−1(t)pi−1 + bi (t)pi , ti ≤ t < ti+1 fi+1(u) f(t) p fi+1(t) = bi (t)pi + bi+1(t)pi+1, ti+1 ≤ t < ti+2 upi+1 i+1 pi−2 fi(u) upi pn−1 pi And for the whole curve: pi−1 p p0 i+2 n−1 n−1

f(t) = ∑fi (t) = ∑bi (t)pi i=1 i=1 ti–1 ti ti+1 ti+2 ti+3 where b (t)’s are the basis functions (in this case, linear) (1u) pi−1 (1u) pi i [Craig] [Craig] Quadratic B-splines de Boor Algorithm Quadratic B-splines (d=2, k=3) are drawn by two De Boor algorithm is an iterative interpolation interpolation steps, similar but different to quadratic algorithm that generalizes de Casteljau’s algorithm Bézier pi–1 To evaluate a B-spline curve f(t) at parameter value t: q i 1/5 4/5 1. determine the [ti, ti+1) in which t belongs; 4/5 qi–1 f(t) d ≤ i < n, the domain of the curve is [td, tn] 1/5 4/5 1/5 2. to compute f(t) of degree d, first interpolate between B-splines quadratic: control points p’s Bézier quadratic: parameter “around” pi 3. r parameter “along” edge control point then, in a bottom up fashion, continue to perform rounds of pairwise linear , until r = d, using: pi–2 r t j+k−r − t r−1 t − t j r−1 Whereas de Casteljau algorithm performs the iterative f j,d (t) = f j−1 (t) + f j (t), t j ≤ t < t j+k−r , t j+k−r − t j t j+k−r − t j interpolations for Bézier curves, de Boor algorithm 1 ≤ r ≤ d, does so for B-splines j = i − d + r, i − d + r +1, …,i [TP3,Buss] [TP3,Buss]

pi–1 pi–1 qi qi q q i–1 f(t) i–1 f(t) Quadratic B-splines B-splines quadratic Quadratic B-splines B-splines quadratic pi pi pi–2 pi–2

Using the de Boor algorithm we first compute qi–1 Then we linearly interpolate between qi–1 and qi in and qi (note: over two knot intervals): a second round (r = 2) of interpolation: t − t t − t 1 i+1 i−1 2 ti+1 − t t − ti qi−1 = fi−1,2 (t) = pi−2 + pi−1, ti−1 ≤ t < ti+1 f (t) = q + q , t ≤ t < t t − t t − t i,2 i−1 i i i+1 i+1 i−1 i+1 i−1 ti+1 − ti ti+1 − ti t − t t − t 1 i+2 i ti+1 − t ti+1 − t qi = fi,2 (t) = pi−1 + pi , ti ≤ t < ti+2 f(t) = p t − t t − t i−2 i+2 i i+2 i ti+1 − ti ti+1 − ti−1 ⎛ t − t t − t t − t t − t ⎞ i+1 i−1 i i+2 p +⎜ + ⎟ i−1 ⎝ ti+1 − ti ti+1 − ti−1 ti+1 − ti ti+2 − ti ⎠

t − ti t − ti + pi ti+1 − ti ti+2 − ti

[TP3,Buss] [TP3,Buss] fi+1(t) fi(t) Quadratic B-splines fi+2(t) Interpolation and Basis Functions

The control point pi influences fi,2(t), fi+1,2(t), and fi+2,2(t), from which we can assemble its blending Bézier B-spline function: ⎧ interpolation de Casteljau de Boor ti+1 − t ti+1 − t ⎪ , ti ≤ t < ti+1, t − t t − t Bernstein Cox-de Boor ⎪ i+1 i i+1 i−1 basis functions polynomials recurrence ⎪ ti+1 − t t − ti−1 t − ti ti+2 − t ⎪ + , ti+1 ≤ t < ti+2 , bi (t) = ⎨ ti+1 − ti ti+1 − ti−1 ti+1 − ti ti+2 − ti ⎪ t − ti t − ti ⎪ , ti+2 ≤ t < ti+3, ⎪ ti+1 − ti ti+2 − ti ⎪ 0, everywhere!else ! ⎩

[TP3,Buss]

Cox-de Boor Recurrence Cubic B-splines de Boor algorithm constructs basis functions “bottom- up”, whereas Cox-de Boor recurrence generates the For 4th order (cubic) B-splines, the basis functions “top-down” recursive definition starts at bi,4(t): Let b (t) be a k-th order basis function for weighting i,k ⎧ ⎪ 1, ti ≤ t < ti+1 base: a step function of 1 control point p , bi,1(t) = ⎨ bi,1(t) i 0, otherwise interval ⎩⎪ ⎧ ⎪ 1, ti ≤ t < ti+1 (both ≤ for last segment), a piecewise linear “tent” b (t) i,1 = ⎨ b (t) function spanning 2 t t t t i,2 ⎪ 0, otherwise linear: − i i+2 − intervals ⎩ bi,2 (t) = bi,1(t) + bi+1,1(t) ti+1 − ti ti+2 − ti+1 a piecewise quadratic t − ti ti+k − t function spanning 3 bi,k (t) = bi,k−1(t) + bi+1,k−1(t) t − ti ti+3 − t bi,3(t) quadratic: bi,3(t) = bi,2 (t) + bi 1,2 (t) intervals ti+k−1 − ti ti+k − ti+1 + ti+2 − ti ti+3 − ti+1 a piecewise cubic • if the denominator is 0 (non-uniform knots), t − t t − t cubic: i i+4 b (t) function spanning 4 bi,4 (t) = bi,3(t) + bi+1,3(t) i,4 the basis function is defined to be 0 t t t t intervals i+3 − i i+4 − i+1 • Cox-de Boor recurrence essentially takes a linear interpolation of linear Illustrated with uniformly spaced knots interpolations of linear interpolations, similar to the de Casteljau algorithm Uniform Cubic Basis Function Local Control Property Constructed from the Cox-de Boor recurrence For uniform, multi-segment B-spline curves, the knot values are equally spaced and each basis function is a copy and translate of each other • taking advantage of fixed interval between knots We define the entire set of curve segments as one B-spline curve in t: • considering only intervals for which the basis function n−1 y(t) P’’ Curve P’’ 4 f(t) = bi (t)pi , t ∈[3,n] 4 is non-zero ∑ P’ = 4 i 0 P’4 Curve P t i i 0 The curve is a linear combination of all 4 Let! i = ,!specializing!for! = : P P Curve ⎧ 1 4 ⎪ 1, ti ≤ t < ti+1 b (t) the basis functions of the segments: P i,1 = ⎨ P 8 0, otherwise 3 P 7 ⎩⎪ ⎧ t 3 b0 (t) b1(t) b2 (t) b3 (t) b4 (t) b5 (t) b6 (t) b7 (t) b8 (t) P Q fQ(u) ⎪ , 0 ≤ t < 1, 0 f3(3u) 5 5 b1,2 (t) = (t − ti )bi,1(t) + (ti+2 − t)bi+1,1(t) Q fQ(6u) 6 f (4u) 6 fQ(u) ⎪ 4 8 8 t − ti ti+3 − t 3 2 P Q 5 f (7u) P bi,3(t) = bi,2 (t) + bi+1,2 (t) ⎪ P2 7 6 Knot 2 2 −3t +12t −12t + 4 , 1 ≤ t < 2, Control point t − t t − t ⎪ Watt 00 x(t) b (t) = i b (t) + i+4 b (t) 6 i,4 i,3 i+1,3 ⎪ domain of curve 3 3 ⎪ 3 2 • each segment is influenced by four b0,4 (t) = ⎨! 3t − 24t + 60t − 44 fb(t()t) (non-zero) basis functions , 2 ≤ t < 3, —6 ⎪ 6 b (t) 6 —5 4 • each control point is scaled by a bi (t) 6 B ⎪ BbiB−s2 Bs bi 1 3 2 —4 —2 —1− single basis function t 12t 48t 64 6 ⎪ − + − + —3 , 3 ≤ t < 4, 6 • each basis function is non-zero —2 ⎪ 6 6 over four successive intervals in t —1 B Bb Bs Bsbi t=i t=i+1 t=i+2 t=i+3 t=i+4 ⎪ 6 i−3 —3 0 each control point influences four 0, everywhere!else tt t t t t t ⎪ 0 1 i i+1 i+2 i+3 i+4 ! ⎩ segments (only) local control [Buss, Shirley, Gleicher] Foley, van Dam 90

f(t) b (t) Convex Hull Property b(u—6) Uniform Cubic B-spline i 6 —5 6 Bb B b —4 iB−s2—2 Bs—i1−1 The basis function is ≥ 0 and sums to 6 Segment Basis Functions —3 6 unity in the range t to t ti ti+1 ti+2 ti+3 ti+4 i i+4 —2 all the control points form a convex hull 6 —1 B B biBs3 Bsbi Basis functions for a single B-spline segment the whole curve is within the convex hull 6 − —3 0 ut 0 1 • shifted pieces of a single basis function to u∈[0,1] range Between knot values, the four basis 3

∑bi−k (t) = 1, ti ≤ t < ti+1 Specializing for i = 0: functions are non-zero and sum to unity k=0 u 3 b (t) ≥ 0, 3 ≤ i < n, 0 ≤ k ≤ 3 b(uf(t)) i − k bi,4 (u) = , u = t,!0 ≤ t < 1 At each knot value, one basis function 6 —6 6 “switches off” and another “switches on”, and 3 2 —5 −3u + 3u + 3u +1 6 Bbi 2 BBs b three basis functions are non-zero and sum to unity bi−1,4 (u) = , u = t −1,!1 ≤ t < 2 —4 B−s—2 —i1−1 6 6 —3 b (t) b (t) b (t) b (t) b (t) b (t) b (t) b (t) b (t) 3 2 6 0 1 2 3 4 5 6 7 8 3u − 6u + 4 —2 b (u) = , u = t − 2,!2 ≤ t < 3 6 i−2,4 1 — Bb BBsb 6 6 iBs−3 —3 0i 3 ut (1− u) 0 1 bi−3,4 (u) = , u = t − 3,!3 ≤ t < 4 ! 6 domain of curve [Shirley, Gleicher] Uniform Cubic B-spline Segment Bézier is Not B-spline

Control points for one segment fi(u) are pi-3, pi-2, Relationship to the control points is different pi-1, pi, 3 ≤ i < n, recall: the control points can take on arbitrary values (geometric constraints)

P y(t) 9 P A segment is described as: 8 Bézier 3 P P t 1 3 P 10 fQ(9u) f5Q(u5) 4 9 P fi (u) = bi 3 j (u)pi 3 j , u ∈[0,1] 7 ∑ − + − + t9 t6 t5 Q j=0 t f88(u) 3 t8 Q Qf66(u) 3 3 2 4 f4(u) P t4 6 (1− u) 3u − 6u + 4 Q t7 f3(u3) Qf 7(u) = pi−3 + pi−2 + 7 6 6 P 5 Knot 3 2 3 P P Control point 3u 3u 3u 1 u 0 2 − + + + x(t) pi−1 + pi 6 6 Foley, van Dam 90 The cubic B-spline segment ⎡ −1 3 −3 1 ⎤ B-spline 1 ⎢ 3 −6 3 0 ⎥ basis matrix is: B = ⎢ ⎥ 6 ⎢ −3 0 3 0 ⎥ ⎣⎢ 1 4 1 0 ⎦⎥ Durand

Interpolation with Interpolation Multiple Control Points A B-spline curve doesn’t have to interpolate any A B-spline curve can be made to interpolate one or of its control points more of its control points by adding multiple control points of the same value, at the loss of continuity Examples:

C2G2

C2G1 C2G0

curve becomes a straight line on either side of the control points Watt 00 Interpolation with Non-uniform B-splines Multiple Control Points Non-uniform B-splines interpolate without causing Multiple control points reduces continuity: the adjacent segments to become linear by using intersection between the two convex hulls shrinks multiple knots instead of multiple control points from a region to a line to a point, and causes the adjacent segments to become linear The interval between ti and ti+1 may be non-uniform;

Q Convex hull 3 when ti = ti+1, curve segment fi is a single point Q4 Convex hull

P0 P2 P4 P0 P3 P0 P4 P y(t) 9 P8

P1 P3 t Q f (u) P 10 f9(9u) 5Q5 4 P7 t9 curve becomes a t6 t5 Qf (u) t 88 Q Q Q straight line on 3 t8 3 4 4 Qf66(u) Q4 either side of the t f4(u) P Q 4 t 6 f3(u3) 7 Qf (u) control points 77 P Q 5 Knot Q3 Q3 4 P0 P Control point P P P = P P P = P = P 2 1 3 1 2 4 1 2 3 x(t) Foley, van Dam 90 Foley, van Dam 90 (a) (b) (c)

Interpolation with Multiple Knots Non-Uniform Uniform B-splines: B-splines Basis Functions

Non-uniform B-splines, Because the intervals between knots are not multiple knots: uniform, there is no single set of basis functions t = [0,1,2,3, 4, 4, 4,5,6, 7,8] f (u) and f (u) (Q and Q in figure) shrinks to 0 4 5 4 5 Instead, the basis functions depend on the intervals between knot values and are defined recursively in terms of lower-order basis functions (using the Cox-

Uniform B-splines, de Boor recurrence) multiple control points: A Bézier curve is really a non-uniform B-splines with

curve doesn’t no (interior) knot between control points curve becomes a become a straight • B-splines can be rendered as a Bézier curve, by inserting straight line on line (though either side of the continuity is still lost) multiple knots at the control points, with no interior knot! control points Watt 00 Rational Curves Rational Cubic Bézier Polynomial curves cannot represent conic sections/ As with homogeneous coordinate, a rational curve is a quadrics exactly–for modeling machine parts, e.g. nonrational curve that has been perspective projected Why not? Cubic Bézier: A conic section in 2D is the • add an extra weight coordinate: wipi = (wixi, wiyi, wizi, wi) perspective projection (wi is the homogeneous coordinate) of a parabola in 3D onto 3 • rational due to division by final weight coordinate: the plane z = 1, with the ∑wibi (u)pi (= perspective divide) f (u) i=0 COP at the origin o f(u) p = 3 w b (u) • projected to z = 1: ∑ i i i=0 Polynomial curves are affine invariant, but not perspective invariant If the wi’s are all equal, we recover Instead, use a rational curve, p (u) the nonrational i.e., a ratio of polynomials: f(u) = 1 fp (u) curve p2 (u) Merrell, Funkhouser, andrews.edu Ramamoorthi, Watt00

Advantages of Rational Curves Role of the Weights (wi’s)

Both affine and perspective invariant For example: larger w1 means that the pre-image, nonrational curve near p1 is “further up” in z, and Can represent conics as rational quadratics the projected image is “pulled” towards p1

Weights (wi’s) provide extra control: values affect “tension” near control points f(u)

• the wi’s cannot all be simultaneously zero

• if all the wi’s are ≥ 0, the curve is still contained in the convex hull of the control polygon moving control point changing weight

fp (u)

[Farin] [Farin,Watt] Non-Uniform Rational B-Splines Advantages of NURBS Most general, can represent: 3 • B-splines cubic NURB control points wi bi,k (u)pi ∑ • Bézier and rational Bézier cubic Bézier control points f(u) = i=0 3 • conic sections ∑ wi bi,k (u) i=0 Properties: with: • local control wi = scalar weight for each control point • convex hull (if wi ≥ 0) p control points i = • variation diminishing (if wi ≥ 0) • wipi = (wi xi ,wi yi ,wizi ,wi ) invariant under both affine and projective transformations

bi,k (u) = the B-splines basis functions Standard tool for representing k = B-splines order freeform curves in CAGD applications

[Farin]

How to Choose a Spline Hermite curves are good for single segments when you know the parametric derivative or want easy control of it Bézier curves are good for single segments or patches where a user controls the points B-splines are good for large continuous curves and surfaces NURBS are the most general, and are good when that generality is useful, or when conic sections must be accurately represented (CAD)

Chenney