cs 184 computer graphics
play

CS-184: Computer Graphics Lecture #5: 3D Transformations and - PowerPoint PPT Presentation

CS-184: Computer Graphics Lecture #5: 3D Transformations and Rotations Prof. James OBrien University of California, Berkeley V2013-F-05-1.0 1 Today Transformations in 3D Rotations Matrices Euler angles Exponential maps


  1. CS-184: Computer Graphics Lecture #5: 3D Transformations and Rotations Prof. James O’Brien University of California, Berkeley V2013-F-05-1.0 1 Today • Transformations in 3D • Rotations • Matrices • Euler angles • Exponential maps • Quaternions 2 2 Tuesday, September 17, 13

  2. 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 3 3 Translations   1 0 t x ˜ A = 0 1 t y 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 4 4 Tuesday, September 17, 13

  3. Scales   s x 0 0 ˜ A = 0 s y 0 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!) 5 5 Shears   1 h xy 0 ˜ A = h yx 1 0 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!) 6 6 Tuesday, September 17, 13

  4. 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 7 7 Rotations • 3D Rotations fundamentally more complex than in 2D • 2D: amount of rotation • 3D: amount and axis of rotation -vs- 2D 3D 8 8 Tuesday, September 17, 13

  5. Rotations • Rotations still orthonormal • Det ( R ) = 1 6 = � 1 • Preserve lengths and distance to origin • 3D rotations DO NOT COMMUTE! • Right-hand rule DO NOT COMMUTE! • Unique matrices 9 9 Axis-aligned 3D Rotations • 2D rotations implicitly rotate about a third out of plane axis 10 10 Tuesday, September 17, 13

  6. Axis-aligned 3D Rotations • 2D rotations implicitly rotate about a third out of plane axis   cos ( θ ) − sin ( θ ) 0  � cos ( θ ) − sin ( θ ) R = sin ( θ ) cos ( θ ) 0 R =   sin ( θ ) cos ( θ ) 0 0 1 Note: looks same as ˜ R 11 11 Axis-aligned 3D Rotations   1 0 0 R = 0 cos ( θ ) − sin ( θ )   x ˆ 0 sin ( θ ) cos ( θ ) “Z is in your face”   cos ( θ ) 0 sin ( θ ) y ˆ R = 0 1 0   y ˆ − sin ( θ ) 0 cos ( θ )   cos ( θ ) − sin ( θ ) 0 x ˆ R = sin ( θ ) cos ( θ ) 0   z ˆ 0 0 1 z ˆ 12 12 Tuesday, September 17, 13

  7. Axis-aligned 3D Rotations   1 0 0 R = 0 cos ( θ ) − sin ( θ )   x ˆ 0 sin ( θ ) cos ( θ ) Also right handed “Zup”   cos ( θ ) 0 sin ( θ ) z ˆ R = 0 1 0   y ˆ − sin ( θ ) 0 cos ( θ ) y ˆ   cos ( θ ) − sin ( θ ) 0 x ˆ R = sin ( θ ) cos ( θ ) 0   z ˆ 0 0 1 13 13 Axis-aligned 3D Rotations • Also known as “direction-cosine” matrices     1 0 0 cos ( θ ) 0 sin ( θ ) R = 0 cos ( θ ) − sin ( θ ) R = 0 1 0     y ˆ x ˆ 0 sin ( θ ) cos ( θ ) − sin ( θ ) 0 cos ( θ )   cos ( θ ) − sin ( θ ) 0 R = sin ( θ ) cos ( θ ) 0   z ˆ 0 0 1 14 14 Tuesday, September 17, 13

  8. Arbitrary Rotations • Can be built from axis-aligned matrices: R = R ˆ z · R ˆ y · R ˆ x • Result due to Euler... hence called Euler Angles • Easy to store in vector • But NOT a vector. R = rot ( x , y , z ) 15 15 Arbitrary Rotations R = R ˆ z · R ˆ y · R ˆ x R ˆ R ˆ R ˆ x y z R 16 16 Tuesday, September 17, 13

  9. Arbitrary Rotations • Allows tumbling • Euler angles are non-unique • Gimbal-lock • Moving -vs- fixed axes • Reverse of each other 17 17 Exponential Maps • Direct representation of arbitrary rotation • AKA: axis-angle, angular displacement vector • Rotate degrees about some axis θ • Encode by length of vector θ r ˆ θ = | r | θ 18 18 Tuesday, September 17, 13

  10. Exponential Maps • Given vector , how to get matrix r R • Method from text: 1. rotate about x axis to put r into the x-y plane 2. rotate about z axis align r with the x axis 3. rotate degrees about x axis θ 4. undo #2 and then #1 5. composite together 19 19 Exponential Maps r x x r x ⊥ ⊥ x • Vector expressing a point has two parts x • does not change x • rotates like a 2D point ⊥ 20 20 Tuesday, September 17, 13

  11. Exponential Maps r x x r x ⊥ ⊥ x x ` = ˆ r ⇥ x x 0 θ − x ⊥ = ˆ r × ( ˆ r × x ) x ⊥ x x 0 = x || + x ` sin ( θ )+ x ? cos ( θ ) x ` sin ( θ ) − x ⊥ cos ( θ ) 21 21 Exponential Maps • Rodriguez Formula x 0 = ˆ r ( ˆ r · x ) + sin ( θ )( ˆ r ⇥ x ) � cos ( θ )( ˆ r ⇥ ( ˆ r ⇥ x )) x Linear in x x r ! ! x Actually a minor variation ... 22 22 Tuesday, September 17, 13

  12. Exponential Maps • Building the matrix x 0 = (( ˆ r t )+ sin ( θ )( ˆ r ˆ r ⇥ ) � cos ( θ )( ˆ r ⇥ )( ˆ r ⇥ )) x   0 − ˆ r z r y ˆ ( ˆ r × ) = r z ˆ 0 − ˆ r x   − ˆ r y r x 0 ˆ Antisymmetric matrix ( a × ) b = a × b Easy to verify by expansion 23 23 Exponential Maps • Allows tumbling • No gimbal-lock! • Orientations are space within π -radius ball • Nearly unique representation • Singularities on shells at 2 π • Nice for interpolation 24 24 Tuesday, September 17, 13

  13. Exponential Maps • Why exponential? • Instead of rotating once by θ , let’s do n small rotations of θ /n r • Now the angle is small, so the rotated x is approximately x 0 x + ( θ /n )ˆ r × x ✓ I + (ˆ r × ) θ ◆ = x x n • Do it n times and you get ( θ /n )ˆ ✓ ◆ n I + (ˆ r × ) θ r × x x 0 = x n 25 25 Exponential Maps ✓ ◆ n I + (ˆ r × ) θ x 0 = lim x n !1 n • Remind you of anything? ⇣ ⌘ n 1 + a is a definition of e a lim n →∞ n • So the rotation we want is the exponential of ! (ˆ r × ) θ • In fact you can just plug it into the infinite series... 26 26 Tuesday, September 17, 13

  14. Exponential Maps • Why exponential? • Recall series expansion of e x 1! + x 2 2! + x 3 e x = 1 + x 3! + ··· 27 27 Exponential Maps • Why exponential? e x • Recall series expansion of • Euler: what happens if you put in for x i θ 1! + − θ 2 2! + − i θ 3 3! + θ 4 e i θ = 1 + i θ 4! + ··· ✓ θ 1 + − θ 2 2! + θ 4 1! + − θ 3 ✓ ◆ ◆ + i = 4! + ··· 3! + ··· = cos ( θ )+ i sin ( θ ) 28 28 Tuesday, September 17, 13

  15. Exponential Maps • Why exponential? r × ) 2 θ 2 r × ) 3 θ 3 r × ) 4 θ 4 r × ) θ = I + ( ˆ r × ) θ + ( ˆ + ( ˆ + ( ˆ e ( ˆ + ··· 1! 2! 3! 4! r × ) 3 = − ( ˆ But notice that: ( ˆ r × ) r × ) 2 θ 2 r × ) θ 3 r × ) 2 θ 4 r × ) θ = I + ( ˆ r × ) θ + ( ˆ + − ( ˆ + − ( ˆ e ( ˆ + ··· 1! 2! 3! 4! 29 29 Exponential Maps r × ) 2 θ 2 r × ) θ 3 r × ) 2 θ 4 r × ) θ = I + ( ˆ r × ) θ + ( ˆ + − ( ˆ + − ( ˆ e ( ˆ + ··· 1! 2! 3! 4! ✓ θ 1! − θ 3 + θ 2 2! − θ 4 ◆ ✓ ◆ r × ) θ = ( ˆ e ( ˆ r × ) 2 + I +( ˆ r × ) 3! + ··· 4! + ··· r × ) θ = ( ˆ e ( ˆ r × ) 2 ( 1 − cos ( θ )) r × ) sin ( θ )+ I +( ˆ 30 30 Tuesday, September 17, 13

  16. Quaternions • More popular than exponential maps e i θ = cos ( θ )+ i sin ( θ ) • Natural extension of • Due to Hamilton (1843) • Interesting history • Involves “hermaphroditic monsters” 31 31 Quaternions • Uber-Complex Numbers q = ( z 1 , z 2 , z 3 , s ) = ( z , s ) q = iz 1 + jz 2 + kz 3 + s i j = k ji = − k i 2 = j 2 = k 2 = − 1 jk = i k j = − i ki = j ik = − j 32 32 Tuesday, September 17, 13

  17. Quaternions • Multiplication natural consequence of defn. q · p = ( z q s p + z p s q + z p × z q , s p s q − z p · z q ) • Conjugate q ∗ = ( − z , s ) • Magnitude || q || 2 = z · z + s 2 = q · q ∗ 33 33 Quaternions • Vectors as quaternions v = ( v , 0 ) • Rotations as quaternions r sin θ 2 , cos θ r = ( ˆ 2 ) • Rotating a vector x 0 = r · x · r ⇤ • Composing rotations Compare to Exp. Map r = r 1 · r 2 34 34 Tuesday, September 17, 13

  18. Quaternions • No tumbling • No gimbal-lock • Orientations are “double unique” || r || = 1 • Surface of a 3-sphere in 4D • Nice for interpolation 35 35 Interpolation 36 36 Tuesday, September 17, 13

  19. Rotation Matrices • Eigen system • One real eigenvalue • Real axis is axis of rotation • Imaginary values are 2D rotation as complex number • Logarithmic formula θ 2sin θ ( R − R T ) ( ˆ r × ) = ln ( R ) = ✓ Tr ( R ) − 1 ◆ θ = cos − 1 2 Similar formulae as for exponential... 37 37 Rotation Matrices • Consider: r r r 1 0 0 ⎡ ⎤ ⎡ ⎤ xx xy xz ⎢ ⎥ ⎢ ⎥ RI r r r 0 1 0 = ⎢ ⎥ yx yy yz ⎢ ⎥ ⎢ r r r ⎥ 0 0 1 ⎢ ⎥ ⎣ ⎦ ⎣ ⎦ zx zy zz • Columns are coordinate axes after (true for general matrices) • Rows are original axes in original system (not true for general matrices) 38 38 Tuesday, September 17, 13

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend