Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Today’s Topics Questions? Piecewise Cubic Parametric curves –Hermite –Bezier –Spline

3 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Curves There are several families of cubic polynomial curve segments that are determined by different things –Hermite determined by the 2 endpoints and the tangent vector at each of the 2 endpoints –Bezier determined by the 2 endpoints P 1 & P 4 and 2 other intermediate points P 2 & P 3 not on the curve –the tangent vectors directions at the end points are P 1 P 2 and P 3 P 4 –which are [P 2 – P 1 ] and [P 4 – P 3 ] (note: this direction was correct) Magnitude is to be defined later this lecture... –Spline determined by 4 specific points Note: there can be higher degree polynomials of these families of curves (see a few slides ahead for a 4 th degree polynomial Bezier curve segment)

4 Bezier Curve segment examples

5 more Bezier Curve segment examples

6 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Recall x(t) = a x t 3 + b x t 2 + c x t + d x y(t) = a y t 3 + b y t 2 + c y t + d y z(t) = a z t 3 + b z t 2 + c z t + d z where 0 <= t <= 1 can be written in matrix form as: Q(t) = [x(t) y(t) z(t)] = T C where T = [t 3 t 2 t 1] and [a x a y a z ] C = [b x b y b z ] [c x c y c z ] [d x d y d z ]

7 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Basis Matrix and Geometry Matrix Q(t) = [x(t) y(t) z(t)] = T C where T = [t 3 t 2 t 1] and [a x a y a z ] C = [b x b y b z ] [c x c y c z ] [d x d y d z ] can be rewritten so that C = M G where –M is a 4x4 matrix called the Basis Matrix and –G is a 4x1 column vector called the Geometry Matrix so Q(t) = T M G

8 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Basis Matrix and Geometry Matrix Q(t) = [x(t) y(t) z(t)] = T M G where T = [t 3 t 2 t 1] and [m 11 m 12 m 13 m 14 ] M = [m 21 m 22 m 23 m 24 ] [m 31 m 32 m 33 m 34 ] [m 41 m 42 m 43 m 44 ] [G 1 ] G = [G 2 ] [G 3 ] [G 4 ] Note: the values of G i are the conditions that define the curve --- such as endpoints and tangent vectors at those end points

9 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Blending functions look at x(t) x(t) = (t 3 m 11 + t 2 m 21 + t m 31 + m 41 )g 1x + (t 3 m 12 + t 2 m 22 + t m 32 + m 42 )g 2x + (t 3 m 13 + t 2 m 23 + t m 33 + m 43 )g 3x + (t 3 m 14 + t 2 m 24 + t m 34 + m 44 )g 4x where g 1x is the x coordinate of G 1 similar equations for y(t) and z(t) the curve is a weighted sum of the elements of the Geometry Matrix where the weights are cubic polynomials of t which are called the Blending Functions the Blending Functions B are given by B = T M, since Q(t) = T M G, Q(t) = B G

10 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Example with lines Before going through an example to find the blending functions from a set of geometry information for parametric cubic polynomials, let's first see how the procedure works with determining the blending functions of a parametric line.

11 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Example with lines Recall the parametric equation of a line: x(t) = x 0 + t ( x end – x 0 ) y(t) = y 0 + t ( y end – y 0 ) z(t) = z 0 + t ( z end – z 0 ) what are the endpoints of the line segment described above? can be rewritten as: x(t) = a x t + b x y(t) = a y t + b y y(t) = a z t + b z

12 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 x(t) = a x t + b x y(t) = a y t + b y y(t) = a z t + b z To get this in the form of Q(t) = T C = T M G T = [ t 1 ] and C = [ a x a y a z ] [ b x b y b z ] C = M G where M = [ m 11 m 12 ] and G = [ g 1x g 1y g 1z ] [ m 21 m 22 ] [ g 2x g 2y g 2z ] Example with lines

13 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 The geometry matrix is simply the two endpoints G = [ G 1 ] = [ g 1x g 1y g 1z ] = [ x 0 y 0 z 0 ] = [ P 0 ] [ G 2 ] [ g 2x g 2y g 2z ] [ x end y end z end ] [ P 1 ] we need to find out the Basis Matrix M M = [ m 11 m 12 ] [ m 21 m 22 ] Q(t) = T M G = [ t 1 ] M G Let's do the rest on the board to figure out M Example with lines

14 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Q(t) = [ t 1 ] M G when t=0, Q(0) is the first endpoint G 1 when t=1, Q(1) is the first endpoint G 2 Q(0) = G 1 = [ 0 1 ] M G and Q(1) = G 2 = [ 1 1 ] M G [ G 1 ] = [ 0 1 ] M [ G 1 ] [ G 2 ] [ 1 1 ] [ G 2 ] Therefore, [ 0 1 ] M = I (the identity matrix) [ 1 1 ] So, to get M, take the inverse of [ 0 1 ] [ 1 1 ] Example with lines

15 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 So, to get M, take the inverse of [ 0 1 ] [ 1 1 ] The inverse of a 2x2 invertible matrix A = [ a 11 a 12 ] = [ a 21 a 22 ] 1 [ a 22 -a 12 ] ---------------- [ -a 21 a 11 ] a 11 a 22 - a 12 a 21 So, M = (1 / (0-1)) [1 -1] = -1 [1 -1] = [ -1 1 ] [-1 0] [-1 0] [ 1 0 ] Example with lines

16 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Q(t) = T M G = [ t 1 ] M G = [ t 1 ] [ -1 1 ] G [ 1 0 ] Recall that T M are the blending functions. What then, are the blending functions of lines? Let's plot them on the board. Example with lines

17 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Q(t) = T C = T M G = [ t 3 t 2 t 1 ] M G M is the 4x4 Basis matrix and G is the Geometry matrix For Hermite curve segments, recall that they are defined with 2 endpoints and the tangents at those endpoints. So, the Geometry matrix is made up of the 2 endpoints and the 2 tangent vectors. The tangent vectors are determined by the derivative of the curve with respect to t at each of the end points (when t=0 and when t=1). x(t) = a x t 3 + b x t 2 + c x t + d x y(t) = a y t 3 + b y t 2 + c y t + d y z(t) = a z t 3 + b z t 2 + c z t + d z where 0 <= t <= 1 x'(t) = 3a x t 2 + 2b x t + c x y'(t) = 3a y t 2 + 2b y t + c y z'(t) = 3a z t 2 + 2b z t + c z Hermite Basis Matrix and Blending Functions

18 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 x'(t) = 3a x t 2 + 2b x t + c x y'(t) = 3a y t 2 + 2b y t + c y z'(t) = 3a z t 2 + 2b z t + c z So, Q'(t) = [ 3t 2 2t 1 0 ] C agreed? Let's call the 2 endpoints in the Geometry Matrix P 1 and P 4 and the 2 tangent vectors at those 2 endpoints R 1 and R 4. [ P 1 ] G = [ P 4 ] [ R 1 ] [ R 4 ] Hermite Basis Matrix and Blending Functions

19 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Let's just work with the x coordinates (the y and z coordinates will be handled similarly) So, x(t) = a x t 3 + b x t 2 + c x t + d x = T C x = [ t 3 t 2 t 1 ] M G x and x'(t) = 3a x t 2 + 2b x t + c x = T C x = [ 3t 2 2t 1 0 ] M G x when t = 0, x(t) gets us the first endpoint and when t = 1, x(t) gets us the other endpoint. x(0) = P 1x = [ 0 0 0 1 ] M G x x(1) = P 4x = [ 1 1 1 1 ] M G x when t = 0, x'(t) gets us the tangent at the first endpoint and when t = 1, x'(t) gets us the tangent at the other endpoint. x'(0) = R 1x = [ 0 0 1 0 ] M G x x'(1) = R 4x = [ 3 2 1 0 ] M G x Hermite Basis Matrix and Blending Functions

20 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 [P 1 ] [ 0 0 0 1 ] [P 4 ] = G x = [ 1 1 1 1 ] M G x [R 1 ] [ 0 0 1 0 ] [R 4 ] x [ 3 2 1 0 ] just like when we solved for M (the basis matrix) with the line equations, we do the same thing here because clearly [ 0 0 0 1 ] [ 1 1 1 1 ] M = Identity [ 0 0 1 0 ] [ 3 2 1 0 ] so, that matrix on the left is equal to M -1 Hermite Basis Matrix and Blending Functions

21 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 There are techniques to get the inverse of a matrix which we won't go into here --- if you've had linear algebra, you should know how. The inverse of [ 0 0 0 1 ] [ 1 1 1 1 ] [ 0 0 1 0 ] [ 3 2 1 0 ] is [ 2 -2 1 1 ] [ -3 3 -2 -1 ] [ 0 0 1 0 ] [ 1 0 0 0 ] This is the Basis Matrix for Hermite curve segments. Let's verify that it is indeed the inverse of the matrix above. How? Hermite Basis Matrix and Blending Functions

22 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 [ 2 -2 1 1 ] T M = [ t 3 t 2 t 1 ] [ -3 3 -2 -1 ] [ 0 0 1 0 ] [ 1 0 0 0 ] The blending functions are: 2 t 3 - 3t 2 + 1 -2 t 3 + 3t 2 t 3 - 2t 2 + t t 3 - t 2 These are respectively multiplied by P 1, P 4, R 1, and R 4 and then added together to get Q(t) which is the curve Hermite Basis Matrix and Blending Functions

23

24 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 [ P 1 ] G 1 = [ P 4 ] [ R 1 ] [ R 4 ] [ P 4 ] G 2 = [ P 7 ] [ kR 4 ] [ R 7 ] If two Hermite curve segments have the above geometry matrices then we can see that they join up at P 4 and that the tangent vectors at P 4 are proportional, hence giving G 1 continuity. If k=1 then C 1 continuity. Using the Geometry matrices to join curves together

25 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 As stated earlier, the pieces of information defining a Bezier curve are 4 points. Therefore, the Geometry Matrix are these 4 points. P 1 and P 4 are the endpoints and P 2 and P 3 are the intermediate points that do not necessarily (usually don't) live on the curve. R 1 (the tangent at the first endpoint) = 3 [P 2 – P 1 ] R 4 (the tangent at the other endpoint) = 3 [P 4 – P 3 ] [ P 1 ] G = [ P 2 ] [ P 3 ] [ P 4 ] Q(t) = [ t 3 t 2 t 1 ] M G Bezier Basis Matrix and Blending Functions

26 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 The Basis Matrix M for Bezier curves is: [ -1 3 -3 1 ] [ 3 6 3 0 ] [ -3 3 0 0 ] [ 1 0 0 0 ] Q(t) = [ t 3 t 2 t 1 ] M G So, what are the blending functions? Bezier Basis Matrix and Blending Functions

27 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 The Blending functions are: -t 3 + 3t 2 -3t + 1 3t 3 + 6t 2 + 3t -3t 3 + 3t 2 t 3 These functions are the Bernstein polynomials which are of the form: C(n, k) t k (1 – t ) n-k where C(n,k) is the choose function. C(n,k) = n! / (k! ((n-k)!)) In the case where n=3 (cubic), we have k among 0,1,2,3, which gives one function per geometric element (point.) Bezier Basis Matrix and Blending Functions

28

29 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 A nice feature of Bezier curves is: –Because the blending functions are symmetric to the lines t and 1-t, the sequence of points used to define a Bezier curve can be reversed without changing the shape of the curve. Both Bezier and Hermite curves are easy to make have G 1 or C 1 continuity at all the join points. It is not easy though to get C 2 continuity at the join points for Hermite and Bezier curves. Hermite and Bezier curves interpolate the points (that is, the curves go through the points). Splines are C 2 continuous. Bezier/Hermite Curves vs. Splines

30 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Splines are C 2 continuous. Natural cubic splines interpolate the control points and the coefficients of a natural cubic spline are dependent on all n control points. –expensive to invert an n+1 by n+1 matrix –moving one control point affects the entire curve B-splines are defined by m+1 control points, where m>=3. The control points are named P 0 through P m. –There are m-2 cubic polynomial, C 2 continuous curve segments joined together. These segments are named Q 3 through Q m. –The join points (as well as the endpoints) of the B-spline are called knots. There are m-1 knots. –moving one control point has only a local effect (that is a good thing) –clearly the B-splines approximate (not interpolate) the control points –Let's look at the handout Splines

31 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Uniform = spacing between knots are equal (that is the difference in t between knots is uniform) –the blending functions for each segment have the same shape but are shifted Nonuniform = spacing between knots are unequal –more flexibility to control the curve shape than uniform –2 or more consecutive knots that are the same reduce the continuity there (e.g., if we have 0 difference between 2 or more knots then continuity is reduced by 1 (i.e., C 2 -> C 1 continuity)) Rational = each spline curve segment is defined as a ratio of polynomials –are invariant under rotation, scaling, translation AND perspective transformations of the control points. So, we apply the perspective transform to the control points and then generate the perspectively transformed curve from the transformed control points to obtain the correct view of the curve. –in addition to the myriad of curves that can be produced, they can precisely define the conic sections (e.g. circle, ellipse, parabola, hyperbola) NURBS = NonUniform Rational B-Splines B-Splines

32 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 NURBS = NonUniform Rational B-Splines –used frequently in graphics packages due to the properties just described Nonrational = each spline curve segment is defined as a polynomial (not a ratio of polynomials) –has the disadvantage (compared to rational B-splines) that they are not invariant to perspective transformations as well as cannot precisely describe the conics B-Splines

33 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Recall that we defined parametric cubic curves as Q(t) = T M G. For surfaces we define a parametric cubic surface with two parameters, hence Q(s,t) for some particular value of s, say s 1, Q(s 1,t) is a parametric curve. Also, for some particular value of t, say t 1, Q(s,t 1 ) is a parametric curve. [ G 1 (t) ] Q(s,t) = S M G(t) = S M [ G 2 (t) ] [ G 3 (t) ] [ G 4 (t) ] Curve Surfaces


Download ppt "CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann."

Similar presentations


Ads by Google