CS-184: Computer Graphics Lecture #3: 2D Transformations Prof. James O Brien Universit of California, Berkele V2006-S-03-1.0 Toda 2D Transformations Primitive Operations Scale, Rotate, Shear, Flip, Translate Homogenous Coordinates SVD Start thinking about rotations... 2
Introduction Transformation: An operation that changes one configuration into another For images, shapes, etc. A geometric transformation maps positions that define the object to other positions Linear transformation means the transformation is defined b a linear function... which is what matrices are good for. 3 Some Eamples Uniform Scale Original Rotation Images from Conan The Destroer, 1984 Shear Nonuniform Scale 4
Mapping Function f () = in old image c() = [195,120,58] c = c( f ()) 5 Linear -vs- Nonlinear Linear (shear) Nonlinear (swirl) 6
Geometric -vs- Color Space Color Space Transform (edge finding) Linear Geometric (flip) 7 Instancing M.C. Escher, from Ghostscript 8.0 Distribution RHW 8
Instancing Reuse geometric descriptions Saves memor RHW 9 Linear is Linear Polgons defined b points Edges defined b interpolation between two points Interior defined b interpolation between all points Linear interpolation 10
Linear is Linear Composing two linear function is still linear Transform polgon b transforming vertices Scale 11 Linear is Linear Composing two linear function is still linear Transform polgon b transforming vertices f () = a + b g( f ) = c + d f g() = c + d f () = c + ad + bd g() = a + b 12
Points in Space Represent point in space b vector in Relative to some origin Relative to some coordinate aes Later we ll add something etra... p = [4,2] T 2 R n 4 Origin, 0 13 Basic Transformations Basic transforms are: rotate, scale, and translate Shear is a composite transformation Uniform/isotropic Non-uniform/anisotropic Rotate Scale Translate Shear -- not reall basic 14
Linear Functions in 2D = f (,) = c 1 + c 2 + c 3 = f (,) = d 1 + d 2 + d 3 [ ] [ ] [ ] [ t M M = + t M M ] = t + M 15 Rotations & Cos( ( ) ' Sin ( )# p ' = $ p % Sin ( ) Cos( ( ) " Rotate 45 degree rotation.707 -.707.707.707 16
Rotations Rotations are positive counter-clockwise Consistent w/ right-hand rule Don t be different... Note: rotate b zero degrees give identit rotations are modulo 360 (or ) 2 17 Rotations Preserve lengths and distance to origin Rotation matrices are orthonormal Det(R) = 1 1 In 2D rotations commute... But in 3D the won t 18
Scales Uniform/isotropic Non-uniform/anisotropic & s 0 # p ' = $ p % 0 s " Scale 0.5 0 0 0.5 0.5 0 0 1.5 19 Scales Diagonal matrices Diagonal parts are scale in X and scale in Y directions Negative values flip Two negatives make a positive (180 deg. rotation) Reall, ais-aligned scales Not ais-aligned... 20
Shears Shear & 1 H # p ' = $ p % H 1 " 1 1 0 1 21 Shears Shears are not reall primitive transforms Related to non-ais-aligned scales More shortl... 22
Translation This is the not-so-useful wa: Translate & t p' = p + $ % t # " Note that its not like the others. 23 Arbitrar Matrices For everthing but translations we have: = A Soon, translations will be assimilated as well What does an arbitrar matri mean? 24
Singular Value Decomposition For an matri, A, we can write SVD: T A = QSR where Q and R are orthonormal and S is diagonal Can also write Polar Decomposition T A = QRSR where Q is still orthonormal not the same Q 25 Decomposing Matrices We can force Q and R to have Det=1 so the are rotations An matri is now: Rotation:Rotation:Scale:Rotation See, shear is just a mi of rotations and scales 26
Composition Matri multiplication composites matrices p ' = BAp Appl A to p and then appl B to that result. p ' = B( Ap) = ( BA) p = Cp Several translations composted to one Translations still left out... p ' = B( Ap + t) = BAp + Bt = Cp + u 27 Composition Transformations built up from others shear shear SVD builds from scale and rotations Also build other was shear i.e. 45 deg rotation built from shears 28
29 Move to one higher dimensional space Append a 1 at the end of the vectors Homogeneous Coordiantes " # $ % & = p p p " # $ $ $ % & = 1 ~ p p p 30 Homogeneous Translation " # $ $ $ % & " # $ $ $ % & = 1 1 0 0 1 0 0 1 ' ~ p p t t p Ap p ~ ~ ' ~ = The tildes are for clarit to distinguish homogenized from non-homogenized vectors.
Homogeneous Others & ~ $ A A = $ % 0 0 0# 0 1" Now everthing looks the same... Hence the term homogenized 31 Compositing Matrices Rotations and scales alwas about the origin How to rotate/scale about another point? -vs- 32
Rotate About Arb. Point Step 1: Translate point to origin Translate (-C) 33 Rotate About Arb. Point Step 1: Translate point to origin Step 2: Rotate as desired Translate (-C) Rotate () 34
Rotate About Arb. Point Step 1: Translate point to origin Step 2: Rotate as desired Step 3: Put back where it was Translate (-C) Rotate () Translate (C) p ~ ' = ( T) RTp ~ = Ap ~ Don t negate the 1... 35 Scale About Arb. Ais Diagonal matrices scale about coordinate aes onl: Not ais-aligned 36
Scale About Arb. Ais Step 1: Translate ais to origin 37 Scale About Arb. Ais Step 1: Translate ais to origin Step 2: Rotate ais to align with one of the coordinate aes 38
Scale About Arb. Ais Step 1: Translate ais to origin Step 2: Rotate ais to align with one of the coordinate aes Step 3: Scale as desired 39 Scale About Arb. Ais Step 1: Translate ais to origin Step 2: Rotate ais to align with one of the coordinate aes Step 3: Scale as desired Steps 4&5: Undo 2 and 1 (reverse order) 40
Order Matters The order that matrices appear in matters A B BA Some special cases work, but the are special But matrices are associative (A B) C = A (B C) Think about efficienc when ou have man points to transform... 41 Matri Inverses In general: Special cases: Translation: negate undoes effect of t and t Rotation: transpose Scale: invert diagonal (ais-aligned scales) Others: A 1 Invert matri Invert SVD matrices A 42
Point Vectors / Direction Vectors Points in space have a 1 for the w coordinate What should we have for a b? w = 0 Directions not the same as positions Difference of positions is a direction Position + direction is a position Direction + direction is a direction Position + position is nonsense 43 Somethings Require Care For eample normals do not transform normall M(a b) (Ma) (Mb) M(Re) R(Me) 44