Modelng curves Types of Curves Graphs: y = ax+b, y = sn(x) Implct ax + by + c = 0, x 2 +y 2 =r 2 Parametrc: x = ax + bxt x = cos t y = ay + byt y = snt Parametrc are the most common mplct are also used, Graphs: not flexble enough (e.g. cannot make a crcle). 1
Parametrc curves Parametrc curve can be thought of as a deformaton of a straght lne. If t s the dstance from some fxed pont of the lne, for each value of t we specfy the correspondng pont n the plane (or space): x = x(t); y = y(t); z = z(t) How do we choose functons x(t) and y(t)? Parametrc curves Typcal requrements: should be easy to use for modelng, that s, makng any desred shape should be smooth (ntuton: f we zoom n should look lke a straght lne), or pecewse smooth should be easy to draw 2
Tangents p(t) p (t+dt) Dervatves of the coordnates defne the tangent: tangent = dp(t) dx(t) dy(t) =, dt dt dt Note: the length of the tangent does not have a geometrc meanng, t depends on parameterzaton. Curvature Intuton: nverse of the radus of the best local approxmaton of the curve by a crcle. x y x y Formula: the dervatves are wth 2 2 3 2 (x + y ) respect to t. R Curvature at t s 1/R p(t) 3
Curvature Curvature measures how straght a curve s at a pont. If curvature s zero everywhere, the curve s a straght lne. y If x = t, curvature s 2 3 2 ( 1 + y ) ; for small y, ths s approxmately the second dervatve. The square of the curvature can be (sometmes) approxmated by x 2 + y 2. The less s the curvature, the ncer s the curve. Modelng We should be able to specfy a small number of ntutve controls; the curve should be automatcally computed from controls. Examples of ntutve controls: Connect the dots approach: specfy several ponts on the curve, draw a nce lne through these ponts; Specfy the drecton (tangent) of the curve n some places Unntutve controls: polynomal coeffcents etc. 4
Real-lfe splnes How was t done before computers? weghts (called ducks) were placed on a sheet of paper at ponts through whch the curve s supposed to pass A flexble steel strp s placed between them A curve s traced out on paper. Idea: try to do somethng smlar; whle modelng physcs s possble, t s somewhat expensve. Try to mtate behavor qualtatvely. Control ponts One possble way of defnng parametrc curves: Defne ponts near whch the curve should pass: p 1 = (x 1,y 1 ), p 2 = (x 2,y 2 )... For each pont p choose a parameter value t. Smplest choce: 1,2,3,... (unform parameterzaton). For each pont specfy a blendng functon B (t), whch defnes how much t contrbutes to the value of the curve at t. x(t) = xb (t) Defne the curve as or p(t) = pb (t) y(t) = y B (t) 5
Blendng functons Requrements for blendng (bass) functons B (t): The control pont p has maxmal nfluence near parameter value ; the further we are from, the less B should be; f we want local control (curve does not change far enough from a control pont) B (t) should be zero for t far from. Should look lke ths: If all control ponts are the same, the resultng curve should be reduced to the same pont. pb = = (t) p B (t) p, so B (t) = 1 Blendng functons Requrements Should be easy to compute (polynomals are); Should be contnuous, and dfferentable (C 1 ), preferably twce (C 2 ). Support (the nterval where t s not zero) should not be too bg. Would be nce to nterpolate the control ponts. Cannot get t all! But can get close f relax one of the requrements. 6
Splnes If gve up on small support, get natural splnes; every control pont nfluences the whole curve. If gve up on nterpolaton, get cubc B-splnes. Cubc B-splne bass functon B-Splnes Need only one bass functon, all B (t) are obtaned by shfts: B (t) = B(t-). The bass functon s pecewse polynomal: B() t = 0 t -2 1 + + + 6 t3 4 2 t t 2 3 t -1 2 t 2 1 3 2 t3 t 0 2 t 2 1 + 3 2 t3 t 1 4 2 t + t 2 1 3 6 t3 t 2 0 2 < t 7
B-splnes The curve wth control ponts p 0, p 2, p 3...p n s computed usng p(t) = n = 0 p B(t ) The allowed range of t s from 1 to n-1; outsde ths nterval our functons do not sum up to 1, whch means n partcular that f we move control ponts together n the same way, the curve outsde the nterval wll not move rgdly. B-splnes The mnmal number of ponts requred s 4; ths corresponds to the nterval for t of length 1. Ths s nconvenent - but we can always add control ponts by reflecton. 8
B-splnes Addng control ponts by reflecton: p n-1 p 1 p n p 0 p n+1 p -1 reflected ponts p -1 = 2p 0 -p 1 ; p n+1 = 2p n -p n-1. Drawng B-splnes Hardware typcally can draw only lne segments. Need to approxmate B-splne wth pecewse lnear curve. Smplest approach: Choose small t. Compute ponts p(0), p( t), p(2 t)... Draw lne segments connectng the ponts. Not very effcent -- have to evaluate a cubc polynomal (or several) at each pont. Can do better usng a magc algorthm (subdvson). 9
B-splnes va subdvson It turns out that the smooth curve can be obtaned by subdvson of the orgnal polylne: Subdvson adds new control ponts between the orgnal control ponts and updates postons of orgnal control ponts. Subdvson Subdvson rules for updatng old ponts: 3/4 1/8 1/8 Subdvson rules for nsertng new ponts: 1/2 1/2 10
Subdvson rules Even rule (n the new sequence of ponts the ponts wth even numbers are the old ponts wth updated postons). j j j ( p + p + p ) j+ 1 p2 = 1 8 1 6 + 1 Odd rule (n the new sequence the ponts wth odd number s a newly nserted pont). j j ( 4p p ) j+ 1 p2+ 1 = 1 8 + 4 + 1 Subdvson Of course, n a fnte number of steps subdvson generates only polylnes. But they get arbtrarly close to a lmt C 2 and ths curve s exactly a cubc B-splne. Algorthm: Start wth an array of control ponts of length n+1. Compute from the orgnal ponts new array of control ponts of length 2n+1 usng subdvson rules for even and odd ponts. Then from the new array compute an array of length 4n+1 etc., (typcally 4-5 steps s enough). Then draw the lne segments connectng sequental control ponts. 11
Endponts What do we do when a pont s mssng? reflected pont In ths case, we apply reflecton (recall addng mssng control ponts). Ths results n the followng trval rule: that s, just keep the old value. j j j j j ( p + 6p + ( p p )) p j+ 1 p0 = 1 8 1 0 2 0 1 = 0 Other splnes There many types of splnes: Bezer, Hermte, Natural, Catmull-Rom,... B-splnes are the most useful, but Bezer and Hermte are used wdely. Bezer are often found n drawng programs (e.g. Powerpont!) although they are not very convenent. 12
Bezer splnes Construct a curve out of segments. For each segment defne 4 ponts: two endponts and two other ponts determnng the tangents at endponts: used for tangents If we ensure that blue ponts on two sdes of each read pont are on one lne, the whole curve s C 1, that s, has a tangent everywhere. Bezer splnes The dea behnd Bezer splnes s to use specal blendng functons for the four ponts, assumng that t s between 0 and 1: (1-t) 3 for p 0, 3t(1-t) 2 for p 1, 3t 2 (1-t) for p 2, and t 3 for p 3. (1-t) 3 t 3 3t(1-t) 2 3t 2 (1-t) 13
Bezer splnes The 4 functons (Bernsten polynomals of order 3), P 0 (t), P 1 (t), P 2 (t), P 3 (t) are (almost) defned by the followng propertes: The sum s 1 for all t the endponts have no nfluence on the poston of the endpont of the curve and on the tangents at opposte endponts. Ths means that P 0 (1) = P 0 (1) =0, P 3 (0) = P 3 (0) =0 Two nteror (blue) control ponts affect only the tangent and at the correspondng endpont, not at the other endpont, and do not affect the postons of the endponts of the curve P 1 (0) =P 1 (1) = P 1 (1) =0, P 2 (1) =P 2 (0) = P 2 (0) =0 All polynomals are cubc and postve Symmetry w.r.t. t=1/2: P 0 (1-t) = P 3 (t), P 1 (1-t) = P 2 (t) Bezer curves The Bezer curves have the followng propertes: endponts are nterpolated tangents at endponts pont towards the nteror control ponts; dervatves are 3(p 1 -p 0 ) and 3(p 3 -p 2 ) respectvely; the curve s n the convex hull of control ponts. The formula for the Bezer curve s p(t) = (1-t) 3 p 0 + 3t(1-t) 2 p 1 + 3t 2 (1-t) p 2 + t 3 p 3 t between 0 and 1. 14