Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Bezier and Spline Curves and Surfaces Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Objectives Introduce the Bezier curves and surfaces Derive the required matrices Introduce the B-spline and compare it to the standard cubic Bezier Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Bezier’s Idea (http://fr.wikipedia.org/wiki/Courbe_de_Bézier) In graphics and CAD, we do not usually have derivative data Bezier suggested using the same 4 data points as with the cubic interpolating curve to approximate the derivatives in the Hermite form Bezier worked for Renault as an engineer (from 1933 to 1975) ; He developed UNISURF in 1971. Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Approximating Derivatives p2 located at u=2/3 p1 located at u=1/3 slope p’(1) slope p’(0) p3 p0 u Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Equations Interpolating conditions are the same p(0) = p0 = c0 p(1) = p3 = c0+c1+c2+c3 Approximating derivative conditions p’(0) = 3(p1- p0) = c0 p’(1) = 3(p3- p2) = c1+2c2+3c3 Solve four linear equations for c and we obtain c=MBp Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Bezier Matrix p(u) = uT c = uT MBp = b(u)T p blending functions Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Blending Functions Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Bernstein Polynomials The blending functions are a special case of the Bernstein polynomials These polynomials give the blending polynomials for any degree Bezier form All zeros of the functions are at 0 and 1 For any degree they all sum to 1 They are all between 0 and 1 inside (0,1) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Convex Hull Property The properties of the Bernstein polynomials ensure that all Bezier curves lie in the convex hull of their control points Hence, even though we do not interpolate all the data, we cannot be too far away p1 p2 convex hull Bezier curve p3 p0 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Bezier Patches Using same data array P=[pij] as with interpolating form Patch lies in convex hull Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Analysis Although the Bezier form is much better than the interpolating form, we STILL have that the derivatives are not continuous at join points Need to align controls points to achieve continuity (see 3rd example in http://www.doc.ic.ac.uk/~dfg/AndysSplineTutorial/Beziers.html) Can we do better? Go to higher order Bezier More work Derivative continuity still only approximate Apply different conditions Tricky without letting order increase Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 B-Splines Splines : http://en.wikipedia.org/wiki/Flat_spline Basis splines: use the data at p=[pi-2 pi-1 pi pi+1]T to define curve only between pi-1 and pi Allows us to apply more continuity conditions to each segment For derivation, see pages 545-547 of reference manual Cost is 3 times as much work for curves Add one new point each time rather than three For surfaces, we do 9 times as much work Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Cubic B-spline p(u) = uTMSp = b(u)Tp Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Cubic B-spline Example : http://www.siggraph.org/education/materials/HyperGraph/modeling/splines/demoprog/curve.html (select B-spline and create 5 points…) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Blending Functions p(u) = uTMSp = b(u)Tp convex hull property Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Joining B-Splines http://www.vis.uni-stuttgart.de/~kraus/LiveGraphics3D/cagd/chap8fig3b.html Move the knots to see the effects Middle knots can change the shape of 4 segments End knots affects 1, 2 or 3 segments Superimposing the first three knots forces the curve to begin at that position Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
B-Spline Patches defined over only 1/9 of region Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Splines and Basis If we examine the cubic B-spline from the perspective of each control (data) point, each interior point contributes (through the blending functions) to four segments We can rewrite p(u) in terms of the data points as defining the basis functions {Bi(u)} Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Splines and Basis Let us study the 4th point of the curve shown in http://www.vis.uni-stuttgart.de/~kraus/LiveGraphics3D/cagd/chap8fig3b.html For the leftmost segment, b3(u) multiplies that point. For the next segment, b2(u) multiplies that point. For the 3rd, it is b2(u). For the 4th, it is b0(u). Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Basis Functions In terms of the blending polynomials (see link on slide 16) Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 To start a B-spline: We can repeat the first node 3 times We can use a phantom control point (see Figure 5.4 in http://www.doc.ic.ac.uk/~dfg/AndysSplineTutorial/BSplines.html - move P1 or P5 to see the effect) We do similarly, at the end of a B-spline. (try repeating last node in http://www.vis.uni-stuttgart.de/~kraus/LiveGraphics3D/cagd/chap8fig3b.html) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Generalizing Splines We can extend to splines of any degree Data and conditions do not have to be given at equally spaced values (the knots) Nonuniform and uniform splines Can have repeated knots Can force spline to interpolate points Cox-deBoor recursion gives method of evaluation http://en.wikipedia.org/wiki/Non-uniform_rational_B-spline Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
NURBS Nonuniform Rational B-Spline curves and surfaces add a fourth variable w to x,y,z Can interpret as weight to give more importance to some control data Can also interpret as moving to homogeneous coordinate Requires a perspective division NURBS act correctly for perspective viewing Quadrics are a special case of NURBS Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 NURBS First, we note that B-spline basis functions can be computed using recurrence relations : http://ibiblio.org/e-notes/Splines/Basis.htm (t0, t1, …ti, tn+k) are called the “knots” and can be selected to fit particular needs Equal spacing of the knots generates “regular” B-spline functions Uneven spacing generates NURBS (in the “second to last” figure of the link above, try moving knots above the basis functions). Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 NURBS http://www.mactech.com/articles/develop/issue_25/schneider.html Figure 7 : uniform basis functions Figure 10 : non-uniform basis functions (obtained by modifying uniform basis functions – using the knots…) In NURBS, repeating 3 times the first and the last three knots brings the curve right on the first and last control points (see slides 18 and 39 in http://www.uqac.ca/daudet/Cours/Infographie/DOCUMENTS/repertoire435/L-09_BSplines_NURBS.pdf Try it using a java applet in http://www.vis.uni-stuttgart.de/~kraus/LiveGraphics3D/cagd/chap8fig3b.html Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009