cs 184 computer graphics
play

CS-184: Computer Graphics Lecture #4: 2D Transformations Prof. - PowerPoint PPT Presentation

CS-184: Computer Graphics Lecture #4: 2D Transformations Prof. James OBrien University of California, Berkeley V2008-F-04-1.0 1 Today 2D Transformations Primitive Operations Scale, Rotate, Shear, Flip, Translate Homogenous


  1. CS-184: Computer Graphics Lecture #4: 2D Transformations Prof. James O’Brien University of California, Berkeley V2008-F-04-1.0 1

  2. Today 2D Transformations “Primitive” Operations Scale, Rotate, Shear, Flip, Translate Homogenous Coordinates SVD Start thinking about rotations... 2 2

  3. 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 by a linear function... which is what matrices are good for. 3 3

  4. Some Examples Uniform Scale Rotation Original Nonuniform Scale Shear 4 Images from Conan The Destroyer , 1984 4

  5. Mapping Function f ( x ) = x in old image c ( x ) = [ 195 , 120 , 58 ] c 0 x = c ( f ( x )) 5 5

  6. Linear -vs- Nonlinear Nonlinear (swirl) Linear (shear) 6 6

  7. Geometric -vs- Color Space Color Space Transform (edge finding) Linear Geometric (flip) 7 7

  8. Instancing RHW 8 M.C. Escher, from Ghostscript 8.0 Distribution 8

  9. Instancing Reuse geometric descriptions Saves memory RHW 9 9

  10. Linear is Linear Polygons defined by points Edges defined by interpolation between two points Interior defined by interpolation between all points Linear interpolation 10 10

  11. Linear is Linear Composing two linear function is still linear Transform polygon by transforming vertices Scale 11 11

  12. Linear is Linear Composing two linear function is still linear Transform polygon by transforming vertices f ( x ) = a + bx g ( f ) = c + d f g ( x ) = c + d f ( x ) = c + ad + bdx g ( x ) = a 0 + b 0 x 12 12

  13. Points in Space R n Represent point in space by vector in Relative to some origin! Relative to some coordinate axes! Later we’ll add something extra... p = [ 4 , 2 ] T 2 4 Origin, 0 13 13

  14. Basic Transformations Basic transforms are: rotate, scale, and translate Shear is a composite transformation! c i p o c r i t p o o s r i t n o a s / i m / m r o r o f i f n i n u U - n o N Rotate Scale Shear -- not really “basic” Translate 14 14

  15. Linear Functions in 2D x 0 = f ( x , y ) = c 1 + c 2 x + c 3 y y 0 = f ( x , y ) = d 1 + d 2 x + d 3 y  �  �  �  � x 0 t x M xx M xy x = + · y 0 t y M yx M yy y x 0 = t + M · x 15 15

  16. Rotations Cos( ) Sin ( ) θ − θ ⎡ ⎤ p ' p = ⎢ ⎥ Sin ( ) Cos( ) θ θ ⎣ ⎦ Rotate 45 degree rotation y .707 -.707 .707 .707 x x 16 16

  17. Rotations Rotations are positive counter-clockwise Consistent w/ right-hand rule Don’t be different... Note: rotate by zero degrees give identity 2 π rotations are modulo 360 (or ) 17 17

  18. Rotations Preserve lengths and distance to origin Rotation matrices are orthonormal Det ( R ) = 1 6 = � 1 In 2D rotations commute... But in 3D they won’t! 18 18

  19. Scales Non-uniform/anisotropic Uniform/isotropic s 0 ⎡ ⎤ x p ' p = ⎢ ⎥ 0 s ⎣ ⎦ y Scale y y y y 0.5 0 0 0.5 0.5 0 0 1.5 19 x x x x 19

  20. 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) Really, axis-aligned scales Not axis-aligned... 20 20

  21. Shears 1 H ⎡ ⎤ yx p ' p = ⎢ ⎥ H 1 ⎣ ⎦ xy Shear y y 1 1 0 1 x x 21 21

  22. Shears Shears are not really primitive transforms Related to non-axis-aligned scales More shortly..... 22 22

  23. Translation This is the not-so-useful way: t ⎡ ⎤ x p ' p = + ⎢ ⎥ t ⎣ ⎦ y Translate Note that its not like the others. 23 23

  24. Arbitrary Matrices For everything but translations we have: x 0 = A · x Soon, translations will be assimilated as well What does an arbitrary matrix mean? 24 24

  25. Singular Value Decomposition For any matrix, , we can write SVD: A T A = QSR where Q and R are orthonormal and S is diagonal Can also write Polar Decomposition T A = QRSR not the same Q where Q is still orthonormal 25 25

  26. Decomposing Matrices We can force Q and R to have Det=1 so they are rotations Any matrix is now: Rotation:Rotation:Scale:Rotation See, shear is just a mix of rotations and scales 26 26

  27. Composition Matrix multiplication composites matrices p = ' BAp “Apply A to p and then apply 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 27

  28. Composition Transformations built up y from others shear SVD builds from scale and rotations shear x x Also build other ways y i.e. 45 deg rotation built y from shears shear x x 28 28

  29. Homogeneous Coordiantes Move to one higher dimensional space Append a 1 at the end of the vectors p ⎡ ⎤ x p ⎡ ⎤ ~ ⎢ ⎥ x p p p = = ⎢ ⎥ y ⎢ ⎥ p ⎣ ⎦ y 1 ⎢ ⎥ ⎣ ⎦ For directions the extra coordinate is a zero 29 29

  30. Homogeneous Translation 1 0 t p ⎡ ⎤ ⎡ ⎤ x x ~ ⎢ ⎥ ⎢ ⎥ p ' 0 1 t p = y y ⎢ ⎥ ⎢ ⎥ 0 0 1 1 ⎢ ⎥ ⎢ ⎥ ⎣ ⎦ ⎣ ⎦ ~ ~ = ~ p ' A p The tildes are for clarity to distinguish homogenized from non-homogenized vectors. 30 30

  31. Homogeneous Others 0 ⎡ ⎤ ~ A ⎢ ⎥ A = 0 ⎢ ⎥ 0 0 1 ⎣ ⎦ Now everything looks the same... Hence the term “homogenized!” 31 31

  32. Compositing Matrices Rotations and scales always about the origin How to rotate/scale about another point? -vs- 32 32

  33. Rotate About Arb. Point Step 1: Translate point to origin Translate (- C ) 33 33

  34. Rotate About Arb. Point Step 1: Translate point to origin Step 2: Rotate as desired Translate (- C ) Rotate ( θ ) 34 34

  35. 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 ) RT p A p = − = Don’t negate the 1... 35 35

  36. Scale About Arb. Axis Diagonal matrices scale about coordinate axes only: Not axis-aligned 36 36

  37. Scale About Arb. Axis Step 1: Translate axis to origin 37 37

  38. Scale About Arb. Axis Step 1: Translate axis to origin Step 2: Rotate axis to align with one of the coordinate axes 38 38

  39. Scale About Arb. Axis Step 1: Translate axis to origin Step 2: Rotate axis to align with one of the coordinate axes Step 3: Scale as desired 39 39

  40. Scale About Arb. Axis Step 1: Translate axis to origin Step 2: Rotate axis to align with one of the coordinate axes Step 3: Scale as desired Steps 4&5: Undo 2 and 1 (reverse order) 40 40

  41. Order Matters! The order that matrices appear in matters A · B 6 = BA Some special cases work, but they are special But matrices are associative ( A · B ) · C = A · ( B · C ) Think about efficiency when you have many points to transform... 41 41

  42. Matrix Inverses A − 1 In general: undoes effect of A Special cases: t x t y Translation: negate and Rotation: transpose Scale: invert diagonal (axis-aligned scales) Others: Invert matrix Invert SVD matrices 42 42

  43. 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 43

  44. Somethings Require Care For example normals do not transform normally M ( a ⇥ b ) 6 = ( Ma ) ⇥ ( Mb ) Use inverse transpose of the matrix for normals. See text book. 44 44

  45. 3D Transformations Generally, the extension from 2D to 3D is straightforward Vectors get longer by one Matrices get extra column and row SVD still works the same way Scale, Translation, and Shear all basically the same Rotations get interesting 45 45

  46. Translations   1 0 t x ˜ 0 1 t y A = For 2D   0 0 1   1 0 0 t x 0 1 0 t y ˜   A = For 3D   0 0 1 t z   0 0 0 1 46 46

  47. Scales   s x 0 0 ˜ 0 s y 0 A = For 2D   0 0 1   s x 0 0 0 0 s y 0 0 ˜   A = For 3D   0 0 s z 0   0 0 0 1 (Axis-aligned!) 47 47

  48. Shears   1 h xy 0 ˜ h yx 1 0 A = For 2D   0 0 1   1 h xy h xz 0 h yx 1 h yz 0 ˜   A = For 3D   h zx h zy 1 0   0 0 0 1 (Axis-aligned!) 48 48

  49. Shears   1 h xy h xz 0 h yx 1 h yz 0 ˜   A =   h zx h zy 1 0   0 0 0 1 Shears y into x 49 49

  50. Rotations 3D Rotations fundamentally more complex than in 2D 2D: amount of rotation 3D: amount and axis of rotation -vs- 2D 3D 50 50

Recommend


More recommend