Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CS-184: Computer Graphics Lecture #5: 3D Transformations and Rotations Prof. James O’Brien University of California, Berkeley V2009-F-05-1.0 Today • Transformations in 3D • Rotations Matrices • Euler angles • Exponential maps • Quaternions • 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 Translations 1 à = 0 0 1 0 0 1 à = 0 0 0 0 0 tx 1 ty 0 1 0 tx 0 ty 1 tz 0 1 For 2D For 3D 4 Scales sx à = 0 0 sx 0 0 sy à = 0 0 0 0 0 sy 0 0 0 sz 0 0 0 1 0 0 0 1 For 2D For 3D (Axis-aligned!) 5 Shears 1 à = hyx 0 1 hxy hyx 1 à = hzx hzy 0 0 hxy 1 0 0 0 1 hxz 0 hyz 0 1 0 0 1 For 2D For 3D (Axis-aligned!) 6 Shears 1 hxy hxz 0 hyx 1 hyz 0 à = hzx hzy 1 0 0 0 0 1 Shears y into x 7 Rotations • 3D • • Rotations fundamentally more complex than in 2D 2D: amount of rotation 3D: amount and axis of rotation -vs2D 3D 8 Rotations • Rotations • still orthonormal Det(R) = 1 != −1 • Preserve • 3D lengths and distance to origin rotations DO NOT COMMUTE! • Right-hand • Unique rule DO NOT COMMUTE! matrices 9 Axis-aligned 3D Rotations • 2D axis rotations implicitly rotate about a third out of plane 10 Axis-aligned 3D Rotations • 2D axis rotations implicitly rotate about a third out of plane ! " cos(θ) − sin(θ) R= sin(θ) cos(θ) cos(θ) − sin(θ) 0 R = sin(θ) cos(θ) 0 0 0 1 Note: looks same as R̃ 11 Axis-aligned 3D Rotations 1 0 0 R = 0 cos(θ) − sin(θ) 0 sin(θ) cos(θ) cos(θ) 0 sin(θ) 1 0 Rŷ = 0 − sin(θ) 0 cos(θ) cos(θ) − sin(θ) 0 Rẑ = sin(θ) cos(θ) 0 0 0 1 x̂ ŷ x̂ ẑ 12 Axis-aligned 3D Rotations 1 0 0 R = 0 cos(θ) − sin(θ) 0 sin(θ) cos(θ) cos(θ) 0 sin(θ) 1 0 Rŷ = 0 − sin(θ) 0 cos(θ) cos(θ) − sin(θ) 0 Rẑ = sin(θ) cos(θ) 0 0 0 1 x̂ “Z is in your face” ŷ x̂ ẑ 12 Axis-aligned 3D Rotations 1 0 0 R = 0 cos(θ) − sin(θ) 0 sin(θ) cos(θ) Also right handed “Zup” cos(θ) 0 sin(θ) ẑ 1 0 Rŷ = 0 − sin(θ) 0 cos(θ) ŷ cos(θ) − sin(θ) 0 x̂ Rẑ = sin(θ) cos(θ) 0 0 0 1 x̂ 13 Axis-aligned 3D Rotations • Also known as “direction-cosine” matrices 1 0 0 Rx̂= 0 cos(θ) − sin(θ) 0 sin(θ) cos(θ) cos(θ) 0 sin(θ) 1 0 Rŷ= 0 − sin(θ) 0 cos(θ) cos(θ) − sin(θ) 0 R ẑ= sin(θ) cos(θ) 0 0 0 1 14 Arbitrary Rotations • Can be built from axis-aligned matrices: • Result R = Rẑ · Rŷ · Rx̂ due to Euler... hence called Euler Angles • Easy to store in vector • But NOT a vector. R = rot(x, y, z) 15 Arbitrary Rotations R = Rẑ · Rŷ · Rx̂ Rx̂ Rŷ Rẑ R 16 Arbitrary Rotations • Allows • Euler tumbling angles are non-unique • Gimbal-lock • Moving • -vs- fixed axes Reverse of each other 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 Exponential Maps • Given vector r , how to get matrix 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 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 Exponential Maps r x⊥ x r x⊥ x x! = r̂ × x x! θ −x⊥ = r̂ × (r̂ × x) x⊥ x x! = x|| + x" sin(θ) + x⊥ cos(θ) x! sin(θ) −x⊥ cos(θ) 21 Exponential Maps • Rodriguez Formula x! = r̂(r̂ · x) +sin(θ)(r̂ × x) −cos(θ)(r̂ × (r̂ × x)) r x! x x! r x Actually a minor variation ... 22 Exponential Maps • Rodriguez Formula x! = r̂(r̂ · x) +sin(θ)(r̂ × x) −cos(θ)(r̂ × (r̂ × x)) r x! x r x! Linear in x x Actually a minor variation ... 22 Exponential Maps • Building the matrix x! = ((r̂r̂t) + sin(θ)(r̂×) − cos(θ)(r̂×)(r̂×)) x 0 −r̂z r̂y 0 −r̂x (r̂×) = r̂z −r̂y r̂x 0 Antisymmetric matrix (a×)b = a × b Easy to verify by expansion 23 Exponential Maps • Allows • No tumbling gimbal-lock! • Orientations • Nearly unique representation • Singularities • Nice are space within π-radius ball on shells at 2π for interpolation 24 Exponential Maps • Why exponential? • Recall series expansion of ex x x2 x3 e = 1+ + + +··· 1! 2! 3! x 25 Exponential Maps • Why exponential? • Recall series expansion of • Euler: what happens if you ex put in iθ for x iθ −θ2 −iθ3 θ4 e = 1+ + + + +··· 1! 2! 3! 4! iθ ! " ! " −θ2 θ4 θ −θ3 = 1+ + +··· +i + +··· 2! 4! 1! 3! = cos(θ) + i sin(θ) 26 Exponential Maps • Why (r̂×)θ e exponential? (r̂×)θ (r̂×)2θ2 (r̂×)3θ3 (r̂×)4θ4 = I+ + + + +··· 1! 2! 3! 4! 3 But notice that: (r̂×) = −(r̂×) (r̂×)θ e (r̂×)θ (r̂×)2θ2 −(r̂×)θ3 −(r̂×)2θ4 = I+ + + + +··· 1! 2! 3! 4! 27 Exponential Maps e(r̂×)θ = I + (r̂×)θ (r̂×)2θ2 −(r̂×)θ3 −(r̂×)2θ4 + + + +··· 1! 2! 3! 4! ! " ! 2 " 3 4 θ θ θ θ e(r̂×)θ = (r̂×) − + · · · + I + (r̂×)2 + − + · · · 1! 3! 2! 4! e(r̂×)θ = (r̂×) sin(θ) + I + (r̂×)2(1 − cos(θ)) 28 Quaternions • More popular than exponential maps • Natural • Due • • iθ extension of e = cos(θ) + i sin(θ) to Hamilton (1843) Interesting history Involves “hermaphroditic monsters” 29 Quaternions • Uber-Complex Numbers q = (z1, z2, z3, s) = (z, s) q = iz1 + jz2 + kz3 + s i2 = j2 = k2 = −1 i j = k ji = −k jk = i k j = −i ki = j ik = − j 30 Quaternions • Multiplication q·p natural consequence of defn. = (zqs p + z psq + z p × zq , s psq − z p · zq) • Conjugate ∗ q = (−z, s) • Magnitude ||q||2 = z · z + s2 = q · q∗ 31 Quaternions • Vectors as quaternions v • Rotations = (v, 0) as quaternions θ θ = (r̂ sin , cos ) 2 2 • Rotating a vector r ! ∗ x = r·x·r • Composing rotations r = r1 · r2 Compare to Exp. Map 32 Quaternions • No tumbling • No gimbal-lock • Orientations • Surface • Nice are “double unique” of a 3-sphere in 4D for interpolation ||r|| = 1 33 Interpolation 34 Rotation Matrices • Eigen system One real eigenvalue Real axis is axis of rotation • Imaginary values are 2D rotation as complex number • • • Logarithmic formula (r̂×) = ln(R) = θ = cos −1 ! θ (R − RT) 2 sin θ Tr(R) − 1 2 " Similar formulae as for exponential... 35 Rotation Matrices • Consider: rxx RI = ryx rzx rxy ryy rzy rxz 1 0 0 ryz 0 1 0 rzz 0 0 1 • Columns are coordinate axes after transformation (true for general matrices) • Rows are original axes in original system (not true for general matrices) 36 Note: • Rotation stuff in the book is a bit weak... luckily you have these nice slides! 37