Euler Angle Formulas David Eberly Magic Software, Inc. http://www.magic-software.com Created: December 1, 1999 1 Introduction Rotations about the coordinate axes are easy to define and work with. Rotation about the x axis by angle θ is 1 0 0 R x (θ) = 0 cos θ sin θ 0 sin θ cos θ where θ > 0 indicates a counterclockwise rotation in the plane x = 0. The observer is assumed to be positioned on the side of the plane with x > 0 and looking at the origin. Rotation about the y axis by angle θ is cos θ 0 sin θ R y (θ) = 0 1 0 sin θ 0 cos θ where θ > 0 indicates a counterclockwise rotation in the plane y = 0. The observer is assumed to be positioned on the side of the plane with y > 0 and looking at the origin. Rotation about the z axis by angle θ is cos θ sin θ 0 R z (θ) = sin θ cos θ 0 0 0 1 where θ > 0 indicates a counterclockwise rotation in the plane z = 0. The observer is assumed to be positioned on the side of the plane with z > 0 and looking at the origin. Rotation by an angle θ about an arbitrary axis containing the origin and having unit length direction U = (U x, U y, U z ) is given by R U (θ) = I + (sin θ)s + (1 cos θ)s 2 where I is the identity matrix, S = 0 U z U y U z 0 U x U y U x 0 1
and θ > 0 indicates a counterclockwise rotation in the plane U (x, y, z) = 0. The observer is assumed to be positioned on the side of the plane to which U points and is looking at the origin. 2 Factoring Rotation Matrices A common problem is to factor a rotation matrix as a product of rotations about the coordinate axes. The form of the factorization depends on the needs of the application and what ordering is specified. For example, one might want to factor a rotation as R = R x (θ x )R y (θ y )R z (θ z ) for some angles θ x, θ y, and θ z. The ordering is xyz. Five other possibilities are xzy, yxz, yzx, zxy, and zyx. One might also envision factorizations such as xyx these are not discussed here. The following discussion uses the notation c a = cos(θ a ) and s a = sin(θ a ) for a = x, y, z. 2.1 Factor as R x R y R z Setting R = [r ij ] for 0 i 2 and 0 j 2, formally multiplying R x (θ x )R y (θ y )R z (θ z ), and equating yields r 00 r 01 r 02 c y c z c y s z s y z s x s y + c x s z c x c z s x s y s z c y s x r 20 r 21 r 22 c x c z s y + s x s z c z s x + c x s y s z c x c y From this we have s y = r 02, so θ y = asin(r 02 ). If θ y ( π/2, π/2), then c y 0 and c y (s x, c x ) = ( r 12, r 22 ) in which case θ x = Tan 1 ( r 12, r 22 ). Similarly, c y (s z, c z ) = ( r 01, r 00 ) in which case θ z = Tan 1 ( r 01, r 00 ). If θ y = π/2, then s y = 1 and c y = 0. In this case r 10 r 11 r 20 r 21 c zs x + c x s z c x c z s x s z c x c z + s x s z c z s x + c x s z sin(θ z + θ x ) cos(θ z + θ x ) cos(θ z + θ x ) sin(θ z + θ x ) Therefore, θ z + θ x = Tan 1 (r 10, r 11 ). There is one degree of freedom, so the factorization is not unique. One choice is θ z = 0 and θ x = Tan 1 (r 10, r 11 ). If θ y = π/2, then s y = 1 and c y = 0. In this case r 10 r 11 r 20 r 21 c zs x + c x s z c x c z + s x s z c x c z + s x s z c z s x c x s z sin(θ z θ x ) cos(θ z θ x ) cos(θ z θ x ) sin(θ z θ x ) Therefore, θ z θ x = Tan 1 2(r 10, r 11 ). There is one degree of freedom, so the factorization is not unique. One choice is θ z = 0 and θ x = Tan 1 2(r 10, r 11 ). Pseudocode for the factorization is thetay = asin(r02); if ( thetay < PI/2 ) if ( thetay > -PI/2 ).. 2
thetax = atan2(-r12,r22); thetaz = atan2(-r01,r00); thetax = -atan2(r10,r11); thetaz = 0; thetax = atan2(r10,r11); thetaz = 0; 2.2 Factor as R x R z R y Setting R = [r ij ] for 0 i 2 and 0 j 2, formally multiplying R x (θ x )R z (θ z )R y (θ y ), and equating yields r 00 r 01 r 02 c y c z s z c z s y s x s y + c x c y s z c x c z c y s x + c x s y s z r 20 r 21 r 22 c x s y + c y s x s z c z s x c x c y + s x s y s z thetaz = asin(-r01); if ( thetaz < PI/2 ) if ( thetaz > -PI/2 ) thetax = atan2(r21,r11); thetay = atan2(r02,r00); thetax = -atan2(-r20,r22); thetay = 0; 3
thetax = atan2(-r20,r22); thetay = 0; 2.3 Factor as R y R x R z Setting R = [r ij ] for 0 i 2 and 0 j 2, formally multiplying R y (θ y )R x (θ x )R z (θ z ), and equating yields r 00 r 01 r 02 c y c z + s x s y s z c z s x s y c y s z c x s y x s z c x c z s x r 20 r 21 r 22 c z s y + c y s x s z c y c z s x + s y s z c x c y thetax = asin(-r12); if ( thetax < PI/2 ) if ( thetax > -PI/2 ) thetay = atan2(r02,r22); thetaz = atan2(r10,r11); thetay = -atan2(-r01,r00); thetaz = 0; thetay = atan2(-r01,r00); thetaz = 0; 2.4 Factor as R y R z R x Setting R = [r ij ] for 0 i 2 and 0 j 2, formally multiplying R y (θ y )R z (θ z )R x (θ x ), and equating yields r 00 r 01 r 02 c y c z s x s y c x c y s z c x s y + c y s x s z s z c x c z c z s x r 20 r 21 r 22 c z s y c y s x + c x s y s z c x c y s x s y s z 4
thetaz = asin(r10); if ( thetaz < PI/2 ) if ( thetaz > -PI/2 ) thetay = atan2(-r20,r00); thetax = atan2(-r12,r11); thetay = -atan2(r21,r22); thetax = 0; thetay = atan2(r21,r22); thetax = 0; 2.5 Factor as R z R x R y Setting R = [r ij ] for 0 i 2 and 0 j 2, formally multiplying R z (θ z )R x (θ x )R y (θ y ), and equating yields r 00 r 01 r 02 c y c z s x s y s z c x s z c z s y + c y s x s z z s x s y + c y s z c x c z c y c z s x + s y s z r 20 r 21 r 22 c x s y s x c x c y thetax = asin(r21); if ( thetax < PI/2 ) if ( thetax > -PI/2 ) thetaz = atan2(-r01,r11); thetay = atan2(-r20,r22); thetaz = -atan2(r02,r00); thetay = 0; 5
thetaz = atan2(r02,r00); thetay = 0; 2.6 Factor as R z R y R x Setting R = [r ij ] for 0 i 2 and 0 j 2, formally multiplying R z (θ z )R y (θ y )R x (θ x ), and equating yields r 00 r 01 r 02 c y c z c z s x s y c x s z c x c z s y + s x s z y s z c x c z + s x s y s z c z s x + c x s y s z r 20 r 21 r 22 s y c y s x c x c y thetay = asin(-r20); if ( thetay < PI/2 ) if ( thetay > -PI/2 ) thetaz = atan2(r10,r00); thetax = atan2(r21,r22); thetaz = -atan2(-r01,r02); thetax = 0; thetaz = atan2(-r01,r02); thetax = 0; 3 Factor Product of Two Given a rotation R that is a product of two coordinate axis rotations, the problem is to factor it into three coordinate axis rotations using the ordering xyz. Derivations for the other orderings are similar. In 6
the subsections the matrices are P x = R x (φ x ), P y = R y (φ y ), and P z = R z (φ z ). Define s a = sin(φ x ), s b = sin(φ y ), s c = sin(φ z ), c a = cos(φ x ), c b = cos(φ y ), and c c = cos(φ z ). 3.1 Factor P x P y This is a trivial case. The factorization is R = R x (φ x )R y (φ y ) = R x (θ x )R y (θ y )R z (θ z ). Therefore, θ x = φ x, θ y = φ y, and θ z = 0. 3.2 Factor P y P x The factorization is R = R y (φ y )R x (φ x ) = R x (θ x )R y (θ y )R z (θ z ). Formal multiplication of the various terms leads to the equation c b s a s b c a s b c y c z c y s z s y 0 c a s a z s x s y + c x s z c x c z s x s y s z c y s x. s b c b s a c a c b c x c z s y + s x s z c z s x + c x s y s z c x c y It is easy to see that s y = c a s b in which case θ y = asin(cos θ y sin θ x ). Adding the 10 and 21 terms yields 0 + c b s a = (c z s x s y + c x s z ) + (c z s x + c x s y s z ) = (1 + s y )(c z s x + c x s z ) which leads to sin(θ x + θ z ) = c b s a /(1 + c a s b ). In the even that c a s b = 1, this leads to a special case in the coding that is easy to solve. Subtracting the 10 term from the 21 term yields c b s a 0 = (c z s x s y + c x s z ) (c z s x + c x s y s z ) = (1 s y )(c z s x c x s z ) which leads to sin(θ x θ z ) = c b s a /(1 c a s b ). In the event that c a s b = 1, this also leads to a special case in the coding that is easy to solve. The sine functions can be inverted and the two resulting equations for θ x and θ z can be solved. For the case c a s b < 1, θ x = 1 2 asin cb s a 1+c b s a + asin cb s a 1 c b s a θ y = asin(c a s b ) θ z = 1 2 asin cb s a 1+c b s a asin cb s a 1 c b s a 3.3 Factor P x P z This is a trivial case. The factorization is R = R x (φ x )R z (φ z ) = R x (θ x )R y (θ y )R z (θ z ). Therefore, θ x = φ x, θ y = 0, and θ z = φ z. 7
3.4 Factor P z P x A construction similar to the case P y P x leads to θ x = 1 c 2 asin a c c c 1+s a s c + asin a c c 1 s a s c θ y = asin(s a s c ) [ ( ) ( θ z = 1 c 2 asin ac c 1+s as c asin )] c ac c 1 s as c 3.5 Factor P y P z This is a trivial case. The factorization is R = R y (φ y )R z (φ z ) = R x (θ x )R y (θ y )R z (θ z ). Therefore, θ x = 0, θ y = φ y, and θ z = φ z. 3.6 Factor P z P y A construction similar to the case P y P x leads to θ x = 1 2 asin cb s c 1+s b c c asin cb s c 1 s b c c θ y = asin(s b c c ) θ z = 1 2 asin cb s c 1+s b c c + asin cb s c 1 s b c c 4 Product of Coordinate Rotation with zyx Factorization Given R = R z (θ z )R y (θ y )R x (θ x ) and coordinate axis rotation P, factor P R = R z (ψ z )R y (ψ y )R x (ψ x ). 4.1 P = P z Trivial case. P = R z (φ z ) and P R = R z (θ z + φ z )R y (θ y )R x (θ x ). Thus, ψ z = θ z + φ z, ψ y = θ y, and ψ x = θ x. 8
4.2 P = P y Set P = R y (φ y ) = P y. Then P R = P y R z R y R x = (P y R z )R y R x = (A z A x A y )R y R x = A z (A x B y )R x = A z (C z C y C x )R x = D z C y D x This requires factorization P y R z = A z A x A y, B y = A y R y, factorization A x B y = C z C y C x, D z = A z C z, and D x = C x R x. 4.3 P = P x Set P = R x (φ y ) = P x. Then P R = P x R z R y R x = (P x R z )R y R x = (A z A x A y )R y R x = A z (A x B y )R x = A z (C z C y C x )R x = D z C y D x This requires factorization P x R z = A z A x A y, B y = A y R y, factorization A x B y = C z C y C x, D z = A z C z, and D x = C x R x. 9