EECS 487: Ineracive Compuer Graphics Lecure 7: B-splines curves Raional Bézier and NURBS Cubic Splines A represenaion of cubic spline consiss of: four conrol poins (why four?) hese are compleely user specified deermine a se of blending funcions There is no single bes represenaion of cubic spline: Cubic Inerpolae? Local? Coninuiy Affine? Convex*? VD*? Hermie C 1 n/a n/a Cardinal (Camull-Rom) excep endpoins C 1 no no Bézier endpoins C 1 naural C 2 n/a n/a B-splines C 2 * n/a when some of he conrol poins are angens no poins Naural Cubic Spline A naural cubic spline s conrol poins: posiion of sar poin 1 s derivaive of sar poin 2 nd derivaive of sar poin posiion of end poin f = a 0 + u 1 a 1 + u 2 a 2 + u a p 0 = f(0) = a 0 + 0 1 a 1 + 0 2 a 2 + 0 a p 1 = f '(0) = a 1 + 2 *0 1 a 2 + *0 2 a p 2 = f ''(0) = 2 *1 1 a 2 + *0 2 a p = f(1) = a 0 + 1 1 a 1 + 1 2 a 2 + 1 a Naural Cubic Spline Given n conrol poins a naural cubic spline has n 1 segmens For segmen i: f i (0) = 1 i = 1 n f i (1) = i = 1 n consrain and basis marices: C = B = C 1 = 1 0 0 0 0 1 0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 2 0 1 1 1 2 1 subsequen segmens assume he posiion and 1 s and 2 nd derivaives of he end poin of he preceding segmen Se: f ' ' i (0) = f i 1 (1) i = 1 n 1 f " " i (0) = f i 1 (1) i = 1 n 1 f 1 " (0) = f n " (1) = 0 O Brien
Naural Cubic Splines Each curve segmen (oher han he firs) receives hree ou of is four conrol poins from he preceding segmen his gives he curve C 2 coninuiy However he polynomial coefficiens are dependen on all n conrol poins conrol is no local: any change in any segmen may change he whole curve curve ends o be ill-condiioned: a small change a he beginning can lead o large subsequen changes B-splines Given n ( d + 1) conrol poins a B-spline curve has n d segmens d is he degree of each B-spline segmen he segmens are numbered d o n 1 for ease of noaion number of conrol poins is independen of he degree unlike a Bézier spline where adding a conrol poin necessarily increases degree by one and unlike muli-segmened Bézier curve where muliple conrol poins supporing a new segmen mus be added a he same ime segmen degree (d) is also curve degree B-splines of degree d are said o have order k (= d + 1) TP Wa Advanages of B-splines Main advanages of B-splines: number of conrol poins no limied by degree (d) auomaic C d 1 coninuiy local conrol To creae a large model wih C 2 coninuiy and local conrol you prey much wan o use cubic B-splines Aside from he firs segmen each B-spline segmen shares he firs d conrol poins wih is preceding segmen sounds like naural spline how can B-splines have local conrol? Local Conrol Unlike naural splines and Bézier curves B-splines conrol poins are no derivaives Insead each segmen is a weighed-sum of d basis funcions (only) giving he conrol poins local conrol Hence Basis spline
Polynomials as a Vecor Space Why is B called he Basis Marix? Polynomials f = a 0 + a 1 u + a 2 u 2 + + a n u n can be added: jus add he coefficiens can be muliplied by a scalar: muliply he coefficiens are closed under addiion and muliplicaion by scalar i.e. he resul is sill a polynomial I s a vecor space! A vecor space is defined by a se of basis linearly independen vecors linear combinaion of he basis vecors spans he space here vecor = polynomial Durand Canonical Power Basis 1 u u 2 u u n are independen any polynomial is a linear combinaion of hese a 0 + a 1 u + a 2 u 2 + + a n u n ofen called he canonical basis funcions Jus as wih Euclidean space here are infinie number of possible basis For cubic he basis funcions could be for example: 1 1+u 1+u+u 2 1+u u 2 +u u u u 2 u +u u +1 Basis Marix and Basis Funcions A basis marix (B) ransforms he canonical basis o anoher basis: f = ua = ubp = (1 u)p 0 + up 1 = ub = n The s are he basis funcions of he oher basis (we ve known hem as he blending funcions) n Durand
B-splines Given n conrol poins here are n d segmens we call he segmens f i d i < n each segmen has a uni range 0 u 1 we call he enire B-spline curve wih n conrol poins f() The parameers i s where wo segmens join are called knos he sar and end poins ( d and n ) are also called knos he range [ d n ] is he domain of a B-spline curve he parameer u of segmen i is scaled o i u < y() P 0 P 2 P 9 P a cubic P 1 P f 5 Q 5 10 fq 9 9 B-spline 4 P 7 9 5 Qf 8 8 Q Qf 8 4 f 4 P f Q 4 7 Qf 77 P 5 P 8 Kno Conrol poin Foley van Dam90 x() Uniform B-splines The knos of a uniform B-splines are spaced a equal inervals y() P 0 P 1 f Q P 2 P 9 P f 5 Q 5 5 P 8 P 4 P 7 f Q 8 Q f 4 4 4 7 Qf 7 7 P 5 10 fq 9 9 9 Qf 8 8 P Kno a cubic B-spline Conrol poin x() Foley van Dam90 Wha Degree is Sufficien? Linear B-spline Segmen Arbirary curves have an uncounable number of parameers In he linear case he basis funcions are b 0 = (1 u) and b 1 = u 1 Real-number funcion value expanded ino an infinie se of basis funcions: f = 0 1 2 (a.k.a. en/riangle basis he i h funcions are shifed versions of he 0 h) Approximae by runcaing se a some reasonable poin e.g. : f = O Brien b = 0 u < 1 1+ u 1 < u < 0 1 u 0 < u < 1 0 u > 1 JamesHanrahan
Linear B-spline Curve Consider using linear B-splines (d=1 k=2) o draw a piecewise linear curve (a polyline) To draw he curve we perform linear inerpolaion of a se of conrol poins p 0 p n 1 = i 1 f i = i+2 p 0 2 p = i+1 i 1 +1 pi+2 p n 1 = i For segmen i we wrie he inerpolaing linear = i+ [ ] curve as f i = (1 u) 1 + u where u = 01 [Craig] Linear B-splines The influence of conrol poin on he whole curve is hus he en/riangle funcion: i < () = < +1 0 everywhere else () 1 1 The hardes par of working wih B-splines is keeping rack of he edious noaions! +1 i +1 [Craig] Linear B-splines Linearly inerpolaing he se of conrol poins o draw he curve: f i = (1 u) 1 + u = 1 + u = i < f i+1 = (1 u) + u+1 = +1 + +1 +1 +1 u = +1 +1 < f() up u+1 2 f i i p0 pi 1 i 1 i i+ (1 u) 1 f i+1 +1 (1 u) +2 pn 1 [Craig] Linear B-splines f i = (1 u) 1 + u = 1 + u = i < f i+1 = (1 u) + u+1 = +1 + +1 +1 +1 u = +1 +1 < We can rewrie he segmen funcions as: f i () = 1 () 1 + () i < f i+1 () = () + +1 ()+1 < And for he whole curve: n 1 f() = f i () = () i=1 where () s are he basis funcions (in his case linear) n 1 i=1 [Craig]
Quadraic B-splines Quadraic B-splines (d=2 k=) are drawn by wo inerpolaion seps similar bu differen o quadraic Bézier 4/5 1/5 4/5 4/5 1/5 1/5 Bézier quadraic: parameer along edge 2 1 q i 1 B-splines quadraic: parameer around conrol poin Whereas de Caseljau algorihm performs he ieraive inerpolaions for Bézier curves de Boor algorihm does so for B-splines f() q i [TPBuss] de Boor Algorihm De Boor algorihm is an ieraive inerpolaion algorihm ha generalizes de Caseljau s algorihm To evaluae a B-spline curve f() a parameer value : 1. deermine he [ i ) in which belongs; d i < n he domain of he curve is [ d n ] 2. o compue f() of degree d firs inerpolae beween conrol poins p s. hen in a boom up fashion coninue o perform r rounds of pairwise linear inerpolaions unil r = d using: r f jd () = j+k r f r 1 j 1 () + j f r 1 j () j+k r j j+k r j < j+k r j 1 r d j = i d + r i d + r +1 i [TPBuss] Quadraic B-splines 1 q i q i 1 f() B-splines quadraic Quadraic B-splines 1 q i q i 1 f() B-splines quadraic Using he de Boor algorihm we firs compue q i 1 and q i (noe: over wo kno inervals): 1 q i 1 = f i 12 () = 2 + 1 1 i 1 < 1 1 q i = f 1 i2 () = 1 + i < 2 Then we linearly inerpolae beween q i 1 and q i in a second round (r = 2) of inerpolaion: f 2 i2 () = q i 1 + q i i < f() = 2 1 2 + +1 1 + 1 1 + [TPBuss] [TPBuss]
Quadraic B-splines f i () f i+1 () f i+2 () Inerpolaion and Basis Funcions The conrol poin influences f i2 () f i+12 () and f i+22 () from which we can assemble is blending funcion: () =! 1 i < 1 1 + < i < i+ 0 everywhere!else Bézier B-spline inerpolaion de Caseljau de Boor basis funcions Bernsein polynomials Cox-de Boor recurrence [TPBuss] Cox-de Boor Recurrence de Boor algorihm consrucs basis funcions boomup whereas Cox-de Boor recurrence generaes he basis funcions op-down Le k () be a k-h order basis funcion for weighing conrol poin 1 1 () = i < (boh for las segmen) 0 oherwise k () = k 1 () + i+k +1k 1 () i+k 1 i+k +1 if he denominaor is 0 (non-uniform knos) he basis funcion is defined o be 0 Cox-de Boor recurrence essenially akes a linear inerpolaion of linear inerpolaions of linear inerpolaions similar o he de Caseljau algorihm Cubic B-splines For 4 h order (cubic) B-splines he recursive definiion sars a 4 (): base: 1 () = linear: quadraic: cubic: 1 i < 0 oherwise 2 () = 1 () + +1 +11 () () = 2 () + i+ i+ +1 +12 () 4 () = i+ () + i+4 i+4 +1 +1 () 1 () 2 () () 4 () a sep funcion of 1 inerval a piecewise linear en funcion spanning 2 inervals a piecewise quadraic funcion spanning inervals a piecewise cubic funcion spanning 4 inervals Illusraed wih uniformly spaced knos
Uniform Cubic Basis Funcion Consruced from he Cox-de Boor recurrence aking advanage of fixed inerval beween knos considering only inervals for which he basis funcion is non-zero 1 1 () = i < 0 oherwise b 12 () = ( )1 () + ( )+11 () () = 2 b () + + i2 +12 () 2 4 () = b () + +4 i +1 () () i i+ i+4 [Buss Shirley Gleicher] Le! i = i!specializing!for!i = 0: b 04 () =!! 0 < 1 +12 2 12 + 4 1 < 2 24 2 + 0 44 2 < +12 2 48 + 4 < 4 0 everywhere!else Local Conrol Propery For uniform muli-segmen B-spline curves he kno values are equally spaced and each basis funcion is a copy and ranslae of each oher We define he enire se of curve segmens as one B-spline curve in : f() = n 1 () [n] The curve is a linear combinaion of all he basis funcions of he segmens: 5 4 2 1 b() B 2 Bs 2 Foley van Dam 90 B Bs b 0 () b 1 () b 2 () b () b 4 () b 5 () b () b 7 () b 8 () B Bs 1 1 B Bs0 0 1 domain of curve b 4 () Wa 00 =i =i+1 =i+2 =i+ =i+4 y() P 1 P 4 P 0 fq P 4 P 4 P 4 Curve P P 2 fq 5 5 Q f Q 4 f 4 P 4 Curve Curve P 4 P 5 fq 7 7 P P 7 f 8 Q8 P8 Kno Conrol poin x() each segmen is influenced by four (non-zero) basis funcions each conrol poin is scaled by a single basis funcion each basis funcion is non-zero over four successive inervals in each conrol poin influences four segmens (only) local conrol Convex Hull Propery The basis funcion is 0 and sums o uniy in he range i o i+4 all he conrol poins form a convex hull he whole curve is wihin he convex hull Beween kno values he four basis funcions are non-zero and sum o uniy A each kno value one basis funcion swiches off and anoher swiches on and hree basis funcions are non-zero and sum o uniy b 0 () b 1 () b 2 () b () b 4 () b 5 () b () b 7 () b 8 () domain of curve b 5 4 2 1 B 2 Bs 2 B Bs B Bs 1 1 B Bs0 0 1 u k () = 1 i < k=0 b i k ( ) 0 i < n 0 k Uniform Cubic B-spline Segmen Basis Funcions () i i+ i+4 Basis funcions for a single B-spline segmen shifed pieces of a single basis funcion o u [01] range Specializing for i = 0: 4 = u 4 =! u =!0 < 1 14 = u + u 2 + u +1 u = 1!1 < 2 24 = u u 2 + 4 u = 2!2 < (1 u) u =! < 4 b 5 B 4 2 Bs 2 2 1 B Bs B Bs 1 1 B Bs0 0 1 u [Shirley Gleicher]
Uniform Cubic B-spline Segmen Conrol poins for one segmen f i are - -2-1 i < n recall: he conrol poins can ake on arbirary values (geomeric consrains) Bézier is No B-spline Relaionship o he conrol poins is differen A segmen is described as: f i = j=0 + j + j u [01] (1 u) = + u u 2 + 4 2 + u + u 2 + u +1 1 + u The cubic B-spline segmen basis marix is: B = 1 y() P 9 P 8 P 1 P P fq 10 Q 5 4 9 5 f 9 P 7 9 5 Q f 8 Q Q 8 f 8 4 f 4 P Q 4 f 7 Qf 77 P 0 P 2 P 5 1 1 0 0 0 1 4 1 0 Kno Conrol poin Foley van Dam 90 x() Bézier B-spline Durand Inerpolaion A B-spline curve doesn have o inerpolae any of is conrol poins Inerpolaion wih Muliple Conrol Poins A B-spline curve can be made o inerpolae one or more of is conrol poins by adding muliple conrol poins of he same value a he loss of coninuiy Examples: C 2 G 2 C 2 G 1 C 2 G 0 curve becomes a sraigh line on eiher side of he conrol poins Wa 00
Inerpolaion wih Muliple Conrol Poins Muliple conrol poins reduces coninuiy: he inersecion beween he wo convex hulls shrinks from a region o a line o a poin and causes he adjacen segmens o become linear Q Convex hull Q 4 Convex hull Non-uniform B-splines Non-uniform B-splines inerpolae wihou causing adjacen segmens o become linear by using muliple knos insead of muliple conrol poins The inerval beween i and may be non-uniform; when i = curve segmen f i is a single poin P 0 P 2 P 4 P 0 P P 0 P 4 y() P 9 P 8 P 1 P f 5 Q 5 P 10 Q 4 f 9 9 P 7 Q Q 4 Q 4 curve becomes a sraigh line on eiher side of he conrol poins 9 5 Q Qf 8 4 f 4 f Q 4 7 Qf 77 Qf 8 8 P P 1 P (a) Q P 1 = P 2 P 4 (b) Q Q 4 P 1 = P 2 = P (c) Foley van Dam 90 P 0 P 2 P 5 Kno Conrol poin Foley van Dam 90 x() Inerpolaion wih Muliple Knos Uniform B-splines: Uniform B-splines muliple conrol poins: curve becomes a sraigh line on eiher side of he conrol poins Non-uniform B-splines muliple knos: = [ 01 2 4 4 4 5 78] f 4 and f 5 (Q 4 and Q 5 in figure) shrinks o 0 curve doesn become a sraigh line (hough coninuiy is sill los) Wa 00 Non-Uniform B-splines Basis Funcions Because he inervals beween knos are no uniform here is no single se of basis funcions Insead he basis funcions depend on he inervals beween kno values and are defined recursively in erms of lower-order basis funcions (using he Coxde Boor recurrence) A Bézier curve is really a non-uniform B-splines wih no (inerior) kno beween conrol poins B-splines can be rendered as a Bézier curve by insering muliple knos a he conrol poins wih no inerior kno!
Raional Curves Polynomial curves canno represen conic secions/ quadrics exacly for modeling machine pars e.g. Why no? A conic secion in 2D is he perspecive projecion of a parabola in D ono he plane z = 1 wih he COP a he origin o Polynomial curves are affine invarian bu no perspecive invarian Insead use a raional curve i.e. a raio of polynomials: f = p 1 p 2 Merrell Funkhouser andrews.edu Raional Cubic Bézier As wih homogeneous coordinae a raional curve is a nonraional curve ha has been perspecive projeced Cubic Bézier: add an exra weigh coordinae: w i = (w i x i w i y i w i z i w i ) (w i is he homogeneous coordinae) raional due o division by final weigh coordinae: (= perspecive divide) f p = projeced o z = 1: f p f w i w i If he w i s are all equal we recover he nonraional curve Ramamoorhi Wa00 Advanages of Raional Curves Boh affine and perspecive invarian Can represen conics as raional quadraics Role of he Weighs (w i s) For example: larger w 1 means ha he pre-image nonraional curve near p 1 is furher up in z and he projeced image is pulled owards p 1 Weighs (w i s) provide exra conrol: values affec ension near conrol poins he w i s canno all be simulaneously zero if all he w i s are 0 he curve is sill conained in he convex hull of he conrol polygon moving conrol poin changing weigh f f p [Farin] [FarinWa]
Non-Uniform Raional B-Splines f = w i k w i k wih: w i = scalar weigh for each conrol poin = conrol poins w i = (w i x i w i y i w i z i w i ) k = he B-splines basis funcions k = B-splines order Advanages of NURBS Mos general can represen: B-splines Bézier and raional Bézier conic secions cubic NURB conrol poins cubic Bézier conrol poins Properies: local conrol convex hull (if w i 0) variaion diminishing (if w i 0) invarian under boh affine and projecive ransformaions Sandard ool for represening freeform curves in CAGD applicaions [Farin] How o Choose a Spline Hermie curves are good for single segmens when you know he parameric derivaive or wan easy conrol of i Bézier curves are good for single segmens or paches where a user conrols he poins B-splines are good for large coninuous curves and surfaces NURBS are he mos general and are good when ha generaliy is useful or when conic secions mus be accuraely represened (CAD) Chenney