CS 4300 Computer Graphics Prof. Harriet Fell Fall 2012 Lecture 11 – September 27, 2012 April 13, 2015 ©College of Computer and Information Science, Northeastern University 1 Today’s Topics • Linear Algebra Review Matrices Transformations • New Linear Algebra Homogeneous Coordinates April 13, 2015 ©College of Computer and Information Science, Northeastern University 2 Matrices a11 a12 A a a 22 21 b11 b12 B b21 b22 b31 b32 b13 b23 b33 c11 c12 c c22 21 C c31 c32 c41 c42 c13 c23 c33 c43 c14 c24 c34 c44 • We use 2x2, 3x3, and 4x4 matrices in computer graphics. • We’ll start with a review of 2D matrices and transformations. April 13, 2015 ©College of Computer and Information Science, Northeastern University 3 Basic 2D Linear Transforms a11 a 21 a12 x a11 x a12 y a22 y a21 x a22 y a11 a12 1 a11 a 21 a22 0 a21 April 13, 2015 a11 a12 0 a12 a 21 a22 1 a22 ©College of Computer and Information Science, Northeastern University 4 Scale by .5 scale .5,.5 .5 0 0 .5 (1, 0) (0.5, 0) (0, 1) (0, 0.5) April 13, 2015 ©College of Computer and Information Science, Northeastern University 5 Scaling by .5 y y 0.5 0 0 0.5 x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 6 General Scaling y y s xs 0 0 1 s x0 0 x s 0 0 ysy 01 0sy x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 7 General Scaling y y scale sx , s y 1 sx 0 x 1 April 13, 2015 sy 0 s y x sx ©College of Computer and Information Science, Northeastern University 8 Rotation cos sin sin cos rot φ sin(φ) cos(φ) -sin(φ) φ cos(φ) April 13, 2015 ©College of Computer and Information Science, Northeastern University 9 Rotation cos sin sin cos rot y y φ x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 10 Reflection in y-axis reflect-y 1 0 0 1 April 13, 2015 ©College of Computer and Information Science, Northeastern University 11 Reflection in y-axis y reflect-y y 1 0 0 1 x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 12 Reflection in x-axis reflect-x 1 0 0 1 April 13, 2015 ©College of Computer and Information Science, Northeastern University 13 Reflection in x-axis y y reflect-x 1 0 0 1 x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 14 Shear-x shear-x s 1 s 0 1 s April 13, 2015 ©College of Computer and Information Science, Northeastern University 15 Shear x y y 1 s 0 1 x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 16 Shear-y shear-y s 1 0 s 1 s April 13, 2015 ©College of Computer and Information Science, Northeastern University 17 Shear y y y 1 0 s 1 x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 18 Linear Transformations • Scale, Reflection, Rotation, and Shear are all linear transformations • They satisfy: T(au + bv) = aT(u) + bT(v) u and v are vectors a and b are scalars • If T is a linear transformation T((0, 0)) = (0, 0) April 13, 2015 ©College of Computer and Information Science, Northeastern University 19 Composing Linear Transformations • If T1 and T2 are transformations T2 T1(v) =def T2( T1(v)) • If T1 and T2 are linear and are represented by matrices M1 and M2 T2 T1 is represented by M2 M1 T2 T1(v) = T2( T1(v)) = (M2 M1)(v) April 13, 2015 ©College of Computer and Information Science, Northeastern University 20 Reflection About an Arbitrary Line (through the origin) y y x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 21 Reflection as a Composition y x April 13, 2015 ©College of Computer and Information Science, Northeastern University 22 Decomposing Linear Transformations • Any 2D Linear Transformation can be decomposed into the product of a rotation, a scale, and a rotation if the scale can have negative numbers. • M = R1SR2 April 13, 2015 ©College of Computer and Information Science, Northeastern University 23 Rotation about an Arbitrary Point y y φ φ x x This is not a linear transformation. The origin moves. April 13, 2015 ©College of Computer and Information Science, Northeastern University 24 Translation (x, y)(x+a,y+b) y y (a, b) x x This is not a linear transformation. The origin moves. April 13, 2015 ©College of Computer and Information Science, Northeastern University 25 Homogeneous Coordinates y y Embed the xy-plane in R3 at z = 1. (x, y) (x, y, 1) x x z April 13, 2015 ©College of Computer and Information Science, Northeastern University 26 2D Linear Transformations as 3D Matrices Any 2D linear transformation can be represented by a 2x2 matrix a11 a12 x a11 x a12 y a 21 a22 y a21 x a22 y or a 3x3 matrix a11 a 21 0 April 13, 2015 a12 a22 0 0 x a11 x a12 y 0 y a21 x a22 y 1 1 1 ©College of Computer and Information Science, Northeastern University 27 2D Linear Translations as 3D Matrices Any 2D translation can be represented by a 3x3 matrix. 1 0 a x x a 0 1 b y y b 0 0 1 1 1 This is a 3D shear that acts as a translation on the plane z = 1. April 13, 2015 ©College of Computer and Information Science, Northeastern University 28 Translation as a Shear y y x x z April 13, 2015 ©College of Computer and Information Science, Northeastern University 29 2D Affine Transformations • An affine transformation is any transformation that preserves co-linearity (i.e., all points lying on a line initially still lie on a line after transformation) and ratios of distances (e.g., the midpoint of a line segment remains the midpoint after transformation). • With homogeneous coordinates, we can represent all 2D affine transformations as 3D linear transformations. • We can then use matrix multiplication to transform objects. April 13, 2015 ©College of Computer and Information Science, Northeastern University 30 Rotation about an Arbitrary Point y y φ φ x April 13, 2015 ©College of Computer and Information Science, Northeastern University x 31 Rotation about an Arbitrary Point y T(cx, cy) R(φ)T(-cx, -cy) φφ φφ April 13, 2015 x ©College of Computer and Information Science, Northeastern University 32 Windowing Transforms (A,B) (a,b) translate (A-a,B-b) scale (C,D) (C-c,D-d) translate (c,d) April 13, 2015 ©College of Computer and Information Science, Northeastern University 33 3D Transformations Remember: x x y y z z 1 A 3D linear transformation can be represented by a 3x3 matrix. a11 a12 a a 21 22 a31 a32 April 13, 2015 a11 a12 a13 a a22 21 a23 a31 a32 a33 0 0 a13 a22 a33 0 0 0 0 1 ©College of Computer and Information Science, Northeastern University 34 3D Affine Transformations sx 0 scale sx , s y , sz 0 0 0 sy 0 0 0 0 sz 0 0 0 0 1 1 0 translate t x , t y , tz 0 0 April 13, 2015 0 1 0 0 0 tx 0 ty 1 tz 0 1 ©College of Computer and Information Science, Northeastern University 35 3D Rotations 0 0 1 0 cos sin rotate x 0 sin cos 0 0 0 rotate z April 13, 2015 0 0 0 1 cos 0 rotate y sin cos sin 0 0 0 sin cos 0 0 0 0 0 0 0 sin 1 0 0 cos 0 0 0 0 0 1 1 0 0 1 ©College of Computer and Information Science, Northeastern University 36