
Rotations in 3D Graphics and the Gimbal Lock Valentin Koch Autodesk Inc. January 27, 2016 Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 1 / 37 Presentation Road Map 1 Introduction 2 2 Rotation Matrices in R 3 3 Rotation Matrices in R 4 Gimbal Lock 5 Quaternions Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 2 / 37 About me MSc. Mathematics with thesis in Mathematical Optimization Principal Research Engineer at Autodesk, Inc. Infrastructure Optimization 3D environment, InfraWorks (similar to Sim City). Encountered Gimbal Lock using numerical optimization algorithms. Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 3 / 37 Presentation Road Map 1 Introduction 2 2 Rotation Matrices in R 3 3 Rotation Matrices in R 4 Gimbal Lock 5 Quaternions Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 4 / 37 Rotation Matrix in R2 Rotation on the unit circle A vector (x; y) of magnitude r, is rotated by an angle t about the origin. We recall that x∗ cos t = ; r y ∗ sin t = ; r and if r = 1, we obtain x∗ = cos t; y ∗ = sin t: Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 5 / 37 Rotation Matrix in R2 Rotating an arbitrary point Given a point (x; y) at an angle α on the unit circle. We want to rotate it by angle β. Hence x∗ = cos(α + β): Using the trig identities, we see that x∗ = cos(α + β) = cos α cos β − sin α sin β = x cos β − y sin β: Similarly, we have y ∗ = y cos β + x sin β: Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 6 / 37 Rotation Matrix in R2 Previous result in Matrix notation Since x∗ = x cos β − y sin β; y ∗ = y cos β + x sin β; we write x∗ cos β − sin β x = y ∗ sin β cos β y 2 and our rotation matrix in R is cos β − sin β R = : sin β cos β Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 7 / 37 Presentation Road Map 1 Introduction 2 2 Rotation Matrices in R 3 3 Rotation Matrices in R 4 Gimbal Lock 5 Quaternions Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 8 / 37 Rotation Matrices in R3 Major axis approach 3 How to extend previous result to R ? General idea: 2 R rotation around major axis x; y, and z Extend the 2x2 matrix to 3x3 Question 3 Why selecting 3 axis to rotate an object in R ? Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 9 / 37 Rotation Matrices in R3 Example rotation about z-axis Example Step 1 Take 2x2 rotation matrix cos γ − sin γ R = sin γ cos γ . Step 2 Extend to 3x3 by adding z-axis, and keep z value unchanged 0cos γ − sin γ 01 Rz = @sin γ cos γ 0A : 001 Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 10 / 37 Rotation Matrices in R3 Basic rotation matrices Given angles α; β, and γ, we obtain the basic rotations about the x-axis 01 0 0 1 Rx = @0 cos α −sinαA ; 0 sin α cos α the y-axis 0 cos β 0 sin β 1 Ry = @ 0 1 0 A ; − sin β 0 cos β and the z-axis 0cos γ − sin γ 01 Rz = @sin γ cos γ 0A : 0 0 1 Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 11 / 37 Rotation Matrices in R3 Disadvantages Why are basic rotation matrices bad? Expensive to correct matrix drifting. Hard to interpolate nicely between two rotations. Gimbal Lock! Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 12 / 37 Rotation Matrices in R3 Matrix drift Matrix drift happens when multiple matrices are concatenated. Round off errors happens on some of the matrix elements, resulting in sheared rotations. Need to orthonormalize the matrix. Gram-Schmidt process is computationally expensive! Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 13 / 37 Rotation Matrices in R3 Linear Interpolation (LERP)) Example π Linearly interpolate between identity I and rotation A, which is 2 around x-axis. 01 0 01 01 0 01 01 0 0 1 R = 0:5 @0 1 0A + 0:5 @0 0 1A = @0 0:5 0:5A 0 0 1 0 −1 0 0 −0:5 0:5 Let u = (0; 1; 0)T . Then kIuk = kAuk = 1. p But kRuk = k(0; 0:5; −0:5)T k = 0:5. So R is not a rotation matrix! You need a Spherical Linear Interpolation (SLERP) for the rotational parts, and LERP for the other parts. Complicated. Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 14 / 37 Presentation Road Map 1 Introduction 2 2 Rotation Matrices in R 3 3 Rotation Matrices in R 4 Gimbal Lock 5 Quaternions Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 15 / 37 Gimbal Lock Sword movement We want to rotate a sword by β = π about the y-axis, and use rotations about the z and y-axis to move the sword down and up again. Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 16 / 37 Gimbal Lock Compose rotation matrices π We first want to rotate to β = 2 . Let R = Rx Ry Rz , which is 01 0 0 1 0 cos β 0 sin β 1 0cos γ −sinγ 01 R = @0 cos α − sin αA @ 0 1 0 A @sin γ cos γ 0A : 0 sin α cos α − sin β 0 cos β 0 0 1 π π Since cos 2 =0, and sin 2 =1, the above becomes 01 0 0 1 0001 1 0cos γ −sinγ 01 R = @0 cos α − sin αA @0 1 0A @sin γ cos γ 0A ; 0 sin α cos α 100 0 0 1 which equals 0 0 0 11 R = @ sin α cos γ + cos α sin γ − sin α sin γ + cos α cos γ 0A : −cosα cos γ + sin α sin γ cos α sin γ + sin α cos γ 0 Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 17 / 37 Gimbal Lock Simplification of rotation matrix Using the facts that sin(α ± γ) = sin α cos γ ± cos α sin γ cos(α ± γ) = cos α cos γ ∓ sin α cos γ we obtain 0 0 0 11 R = @ sin(α + γ) cos(α + γ) 0A − cos(α + γ) sin(α + γ) 0 Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 18 / 37 Gimbal Lock Loosing a degree of freedom π −π From β = 0 to 2 , we now want to rotate 6 about the z-axis, and from π −π β = 2 to π, we want to rotate 6 about the x-axis. But since 0 0 0 11 R = @ sin(α + γ) cos(α + γ) 0A ; − cos(α + γ) sin(α + γ) 0 is a rotation matrix about the z-axis, changing α or γ has the same effect! The angle α + γ may change, but the rotation happens always about the z-axis with unexpected results. Watch this Video by PuppetMaster's 3D experiences, CC-BY. Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 19 / 37 Gimbal Lock Euler angles Using Euler angles to steer pitch, roll, and yaw. Pictures by MathsPoetry, CC BY-SA Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 20 / 37 Rotation Alternatives How to avoid Gimbal Lock? There are alternative rotations: Euler angles Axis-angle representation Quaternions Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 21 / 37 Axis angle representation Euler vector A rotation vector r = θe^; T wheree ^ = (ex ; ey ; ez ) is an arbitrary unit vector, and θ is the angle of rotation about the axise ^. No Gimbal Lock. Combining two rotations defined by Euler vectors is not simple. Cannot use LERP to interpolate. Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 22 / 37 Presentation Road Map 1 Introduction 2 2 Rotation Matrices in R 3 3 Rotation Matrices in R 4 Gimbal Lock 5 Quaternions Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 23 / 37 Quaternions The holy grail of 3D rotations Introduced by William Rowan Hamilton in 1843 An extension to complex numbers from two dimensions to three i 2 = j2 = k2 = ijk = −1 by JP, CC BY-SA 2.0 Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 24 / 37 Quaternions Representation Definition A quaternion is a quadruple formed by a scalar w, and a vector v = (x; y; z). We write it as q = (w; v): Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 25 / 37 Quaternions Unit Quaternions 3 Any rotation in R can be represented by a unit quaternion. Definition A unit quaternion is a quaternion q, such that kqk = 1, where kqk = w 2 + x2 + y 2 + z2. 4 All unit quaternions form a hypersphere in R . Rotations happen on the surface of this hypersphere. Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 26 / 37 Quaternions From axis-angle to quaternions Given an axis defined by unit vector u = (ux ; uy ; uz ); and an angle θ: How do I obtain a rotation quaternion? Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 27 / 37 Quaternions 2 Complex numbers and R 2 Any point in R can be represented by a complex number, where the real part lays on the x-axis, and the imaginary part on the y-axis. Euler's formula relates the trigonometric functions to the exponential function by gunther and Wereon, CC BY-SA 3.0 Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 28 / 37 Quaternions Extending Euler's Formula Let i = (1; 0; 0)T ; j = (0; 1; 0) and k = (0; 0; 1). Given u and θ, an extension to Euler's Formula says that wv θ (u i+u j+u k) θ θ e = e 2 x y z = cos + sin (u i + u j + u k): 2 2 x y z Conversion of an axis-angle to a rotation quaternion 3 Given a unit vector u = (ux ; uy ; uz ) 2 R and a rotation angle θ about u, the corresponding unit quaternion q is θ θ q = (cos ; sin u): 2 2 Valentin Koch (ADSK) IEEE Okanagan January 27, 2016 29 / 37 Quaternions Axis-angle to quaternion example Example We want to rotate 90◦ about the y-axis using a quaternion.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages37 Page
-
File Size-