13.07.2015 Views

Bezier Curves and Surfaces (Redbook ch12)

Bezier Curves and Surfaces (Redbook ch12)

Bezier Curves and Surfaces (Redbook ch12)

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Bezier</strong> <strong>Curves</strong> <strong>and</strong> <strong>Surfaces</strong>(<strong>Redbook</strong> <strong>ch12</strong>)27 March 2007CMPT370Dr. Sean HoTrinity Western University


Review last time● Bump mapping theory Creating a texture in OpenGL● Texture objects: glBindTexture()● Loading image data: glTexImage2D() Using the framebuffer as a texture Applying a texture in OpenGL● Blending modes: glTexEnvf()● Texture coordinates: glTexCoord2f() Auto-generated texcoords: glTexGen() Spherical environmental mapping● Mip-mapsCMPT370: <strong>Bezier</strong> curves 27 Mar 20072


What's on for today Polynomial curves <strong>and</strong> surfaces Cubic polynomial curves:● Interpolating (4 points)● Hermite (2 points + 2 derivatives)● <strong>Bezier</strong> (2 interpolating end points + 2midpoints)● Using <strong>Bezier</strong> evaluators in OpenGLCMPT370: <strong>Bezier</strong> curves 27 Mar 20073


Parametric representation Recall a 1D curve in 3D can be represented as:[ xup u= yuzu]xp u=[ ' 'y ' z u] ' p'(u) is the tangent (velocity) vector● Usually limit u to interval [0,1] for simplicity For surfaces we have two parameters (u, v):pu ,v=[xu , v]yu , vzu , v∂ p[ ∂ x/∂u]∂ u u , v= ∂ y/∂ u∂ z/∂ u∂ p[ ∂ x/∂v]∂ v u , v= ∂ y/∂ v∂ z/∂ vCMPT370: <strong>Bezier</strong> curves 27 Mar 20074


Polynomial curves Restrict the functions x(u), y(u), z(u) to bepolynomial (of degree n) in u:● Each coefficient c kis a 3-vector● u k are the n+1 basis functions● Often choose n=3: cubic polynomial k=0..3, (x,y,z): need 12 numbers Similarly for surfaces:np u ,v=∑j=0np u=∑k =0n∑k =0c ku kc jku j v kCMPT370: <strong>Bezier</strong> curves 27 Mar 20075


Interpolating Cubic Polynomials Simplest case, but rarely used in practice Four control points p 0, ..., p 3 Fit a cubic polynomial through them● Space u evenly: p 0= p(0), p 1=[= p(1/3), ...1p 0c 2 2 p 1]3c3 3 p 21 2 pp 3= p1=c 0c 1c 2c 33 2 23 3p 0 = p0=c 0p 1= p 1 3 =c 0 1 3 c 1 1 3 2c 2 1 3 3c 3p 2 = p 2 3 =c 0 2 3 c 1 2 3 2[0 0 01 1 3 1 3 2 1 3 3 2 3 31 1 1 1][c0c 1]c 2c 3CMPT370: <strong>Bezier</strong> curves 27 Mar 20076


Geometry matrix Invert this matrix to get the geometry matrix● Multiply the geometry matrix by the fourcontrol points to get the coefficients[c 0c 1] =[1 0 0 0] [p 0−5.5 9 −4.5 1 p 1]c 29 −22.5 18 −4.5 p 2c 3−4.5 13.5 −13.5 4.5 p 3 The coefficients define the cubic polynomial thatinterpolates these control points● Can render, e.g., by using many small linesegments (GL_LINE_STRIP)CMPT370: <strong>Bezier</strong> curves 27 Mar 20077


Blending functions We can also look at the contribution each controlpoint makes to the final curve For interpolating cubics:● p(u) = b 0(u) p 0+ b 1(u) p 1+ b 2(u) p 2+ b 3(u) p 3CMPT370: <strong>Bezier</strong> curves 27 Mar 20078


Hermite polynomial curves Another way of defining cubic polynomials Specify start+end position+velocity● Also 12 numbers In matrix form:[p 0'p 0] =[1p 3'p 30 0 00 1 0 01 1 1 10 1 2 3]● Invert to get Hermite geometry matrixfrom which we get the coefficients[c0c 1]c 2c 3CMPT370: <strong>Bezier</strong> curves 27 Mar 20079


Joining polynomial curves Each segment has 4 control points● {p 0, p 1, p 2, p 3}, {p 3, p 4, p 5, p 6}, ... Kinds of continuity: differential:● C 0 : touching but may have corner● C 1 : derivatives match (Hermite)● C 2 : curvatures match Geometric continuity:● G 1 : velocity vectors in samedirection but not necessarilysame magnitudeCMPT370: <strong>Bezier</strong> curves 27 Mar 200710


<strong>Bezier</strong> curves Widely used, provided in OpenGL Use control points to indicate tangent vectors● Does not interpolate middle control points!● p'(0) = 3(p 1–p 0), p'(1) = 3(p 3–p 2) p 0, p 3specify start+end position start+end velocity derived from control points Use Hermite form[c 0c C 0 but not C 11] =[1 0 0 0] [p−3 3 0 0c 23 −6 3 0c 3−1 3 −3 10p 1]p 2p 3CMPT370: <strong>Bezier</strong> curves 27 Mar 200711


<strong>Bezier</strong> blending functions Blending functions are smooth polynomials b 0(u) = (1-u) 3 b 1(u) = 3u(1-u) 2 b 2(u) = 3u 2 (1-u) b 3(u) = 3u 3CMPT370: <strong>Bezier</strong> curves 27 Mar 200712


PR EFACIO.cuentran continuamente en las actas del. Qoncilie'Tridentino.«Semper hæc fides in Ecclesia Dei fuit.» Sees. un. capitulo3. (1)«Ideo persuasum semper in Ecclesia Dei fuit, 'idque nunc


<strong>Bezier</strong> evaluators in OpenGL Specify array (1D or 2D) of control points: GLfloat ctrlpoints[4][3] = { {-4.0, -4.0, 0.0}, ... Create a <strong>Bezier</strong> evaluator: (type=GL_MAP1_VERTEX_3) glMap1f( type, u min, u max, stride, order, points ); Enable the evaluator: glEnable( type ); Evaluate the <strong>Bezier</strong> at a particular u/v: glEvalCoord1f( (GLfloat) u );● Use this instead of glVertex(), e.g., withinglBegin( GL_LINE_STRIP )CMPT370: <strong>Bezier</strong> curves 27 Mar 200714

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!