Download presentation
Presentation is loading. Please wait.
1
GAM 325/425: Applied 3D Geometry
Lecture 4, Part C: (Extra Topics) Converting Rotations From Matrix Form to Euler Angles
2
Problem: Convert Rotation Matrix to Euler Angles
Problem: You have an object positioned in space with a matrix W = TRS and you need to extract the Euler angles from R to position the rotation widgets for a GUI.
3
Problem: Convert Rotation Matrix to Euler Angles
Problem: You have an object positioned in space with a matrix W = TRS and you need to extract the Euler angles from R to position the rotation widgets for a GUI. Assumptions: We know the axis order explicitly. For example: We ignore T and S and letβs say that π= β0.146 β0.5 β β0.5 What are the angles π π₯ , π π¦ and π π§ ? If we know that π= π π₯ π π¦ π π§ = cos π π₯ β sin π π₯ 0 sin π π₯ cos π π₯ cos π π¦ 0 sin π π¦ β sin π π¦ 0 cos π π¦ cos π π§ β sin π π§ 0 sin π π§ cos π π§ = cos π π¦ cos π π§ β cos π π¦ sin π π§ sin π π¦ β¦ β¦ β sin π π₯ cos π π¦ β― β¦ cos π π₯ cos π π¦ Any ideas? π 1,3 = sin π π¦ therefore, π π¦ = sin β1 π 1,3 Without the axis order known, the problem is not solvable
4
Problem: Convert Rotation Matrix to Euler Angles
We have that: π= β0.146 β0.5 β β0.5 = cos π π¦ cos π π§ βcos π π¦ sin π π§ sin π π¦ β¦ β¦ β sin π π₯ cos π π¦ β― β¦ cos π π₯ cos π π¦ π 1,3 = π ππ π π¦ therefore: π π¦ = sin β1 π 1,3 = sin β1 (0.707) Using calculator, we get π π¦ = π 4 (45 deg) But is it? Problem: There are an infinite number of angles for which sin π π¦ =0.707 0.707
5
Trigonometric Functions and Their inverses
When dealing with angles in general, we usually limit the range of options to one full circles. Typically this means one of these ranges: [0, 2ο°] or [-ο°, ο°] Weβll be using [-ο°, ο°] but everything we do here could be adapted to [0, 2ο°] Problem: Even on the restricted range [-ο°, ο°], inverting the sine function still offers two possible angle for the same sine valueβ¦ 0.707 And of course, the same is true for Cosine, Tangent, etc.
6
Trigonometric Functions and Their inverses
Most implementation of inverse trig functions use a specific range: Inverse cosine range, cos β1 π : [0, ο°] Inverse sine range, sin β1 π : β π 2 , π 2 Inverse tangent, tan β1 π : β π 2 , π 2 Letβs see how much this helps using different angles: Sidebar: Inverse trigonometric functions are also called arcsine, arccosine, arctangent etc. Giving us the alternate notation acos, asin, etc. Actual angle sin sin β1 π 4 0.707 3π 4 β 3π 4 -0.707 β π 4 Clearly, we donβt have enough information to correctly identify the initial angle
7
Trigonometric Functions and Their inverses
What if we considered sine and cosine jointly? In general: seeing both values of sine and cosine (specifically, their signs) allows us to determine the proper quadrant of the angle and therefore correctly adjust the answer we get from inverse trigs. Itβs a bit fiddly thoughβ¦ Fortunately, somebody did the work for usβ¦ Actual angle sin cos sin β1 Adjusted angle π 4 0.707 + 3π 4 - πβ π 4 = 3π 4 β 3π 4 -0.707 β π 4 βπβ βπ 4 = β3π 4
8
Inverse Tangent and ATan2
As you know: tan π = sin π cos π , so could we use the inverse tangent to unambiguously identify the original angle? Sadly, no: the inverse tangent, tan β1 π , has the range β π 2 , π 2 But what if we defined the inverse tangent in terms of both the sine and cosine? Thatβs what ATan2 is forβ¦ Actual ο± tan π½ tan β1 π½ π 4 1 3π 4 -1 β π 4 β 3π 4 Again, we are losing the quadrant information
9
Inverse Tangent and ATan2
ATan2 was specifically created by computer scientists to expand on the inverse tangent: it correctly returns the angle based on the quadrant information. tan β1 π has the range β π 2 , π 2 Half circle ATan2 π¦,π₯ has the range [-ο°, ο°] Full circle ATan2 π¦,π₯ = tan β1 π¦ π₯ π₯>0 tan β1 π¦ π₯ + π π₯<0, π¦β₯0 tan β1 π¦ π₯ β π π₯<0, π¦<0 π 2 π₯=0, π¦>0 β π 2 π₯=0,π¦<0 π’ππππππππ π₯=π¦=0 Therefore, if we have access to both sine and cosine values, ATan2 will correctly return the angle in the range [-ο°, ο°] So letβs use this for converting rotation matrices to Euler anglesβ¦ Quadrant 1 and 4 Quadrant 2 Quadrant 3 Corrects for division by 0 Varies by implementation
10
Convert Rotation Matrix to Euler Angles
Case 1: (Simple case) The rotation matrix R is ONE of π π₯ , π π¦ or π π§ Ex: π= π π₯ = cos π π₯ β sin π π₯ 0 sin π π₯ cos π π₯ If π= β0.383 β β then ATan , β = ? We clearly have access to sin π π₯ and cos π π₯ , so ATan2 π 32 , π will work Similarly if π= π π or π= π π ATan2 π¦,π₯ = tan β1 π¦ π₯ π₯>0 tan β1 π¦ π₯ + π π₯<0, π¦β₯0 tan β1 π¦ π₯ β π π₯<0, π¦<0 π 2 π₯=0, π¦>0 β π 2 π₯=0,π¦<0 π’ππππππππ π₯=π¦=0 ATan , β = (or deg)
11
Convert Rotation Matrix to Euler Angles
Case 2: The rotation matrix R is the product of TWO of π π₯ , π π¦ or π π§ Example: If we have R such that π= π π₯ π π¦ = cos π π₯ β sin π π₯ 0 sin π π₯ cos π π₯ cos π π¦ 0 sin π π¦ β sin π π¦ 0 cos π π¦ = cos π π¦ 0 sin π π¦ sin π π₯ sin π π¦ cos π π₯ β sin π π₯ cos π π¦ β cos π π₯ sin π π¦ sin π π₯ cos π π₯ cos π π¦ Again, we have access to sin π π₯ and cos π π₯ , so ATan2 π 32 , π will work for π π₯ . We also have access to sin π π¦ and cos π π¦ , so ATan2 π 13 , π will work for π π¦ . A similar reasoning will work for all six pairs combinations of π π₯ , π π¦ and π π§ (remember: matrix multiplication is not commutativeβ¦) with only the location of the entries for sin and cos varying depending the specific pairing. So, what about R constructed as a proper Euler angle rotation using 3 simple rotations?
12
Convert Rotation Matrix to Euler Angles
Case 3: The rotation matrix R is the product of THREE of π π₯ , π π¦ or π π§ Example: If R is such that π= π π₯ π π¦ π π§ = cos π π₯ β sin π π₯ 0 sin π π₯ cos π π₯ cos π π¦ 0 sin π π¦ β sin π π¦ 0 cos π π¦ cos π π§ β sin π π§ 0 sin π π§ cos π π§ = cos π π¦ cos π π§ βcos π π¦ sin π π§ sin π π¦ β¦ β¦ β sin π π₯ cos π π¦ β― β¦ cos π π₯ cos π π¦ Now we have a problem: We donβt have any sine and cosine pairsβ¦ The best we have is the lonely sin π π¦ . At best: we have two solutions from computing sin β1 π 13 : π π¦1 = sin β1 π 13 π π¦2 = πβ π π¦1 if π π¦1 β₯0 βπβ π π¦1 if π π¦1 <0 But how can we find π π₯ and π π§ ?
13
Convert Rotation Matrix to Euler Angles
π= π π₯ π π¦ π π§ = cos π π¦ cos π π§ βcos π π¦ sin π π§ sin π π¦ β¦ β¦ β sin π π₯ cos π π¦ β― β¦ cos π π₯ cos π π¦ Consider π 11 and π 12 . Using π π¦1 , we can compute π 11 cos π π¦1 = cos π π§ and βπ 12 cos π π¦1 = sin π π§ Since we now have both sin π π§ and cos π π§ , we use ATan2 to uniquely identify π π§1 Similarly, Using π π¦2 we can compute an alternate unique π π§2 Now consider π 23 and π 33 Again, using π π¦1 and π π¦1 , we can compute both sin π π₯ and cos π π₯ for each. Using ATan2, we obtain π π₯1 and π π₯2 This gives us two solutions for the original matrix, based on the original π π¦ Solution 1: The three angles are π π₯1 , π π¦1 and π π§1 Solution 2: The three angles are π π₯2 , π π¦2 and π π§2 Unless we have external information to determine which is the correct π π¦ , we canβt be more precise
14
Convert Rotation Matrix to Euler Angles
Example: Assume we have π= π π₯ π π¦ π π§ = cos π π¦ cos π π§ βcos π π¦ sin π π§ sin π π¦ β¦ β¦ β sin π π₯ cos π π¦ β― β¦ cos π π₯ cos π π¦ Find the Euler angles if π= β0.146 β0.5 β β0.5 Based on the previous slides: π π¦1 = sin β =0.785 (45 deg) π π¦2 =πβ sin β =2.356 (135 deg) If π π¦ = π π¦1 =0.785 then cos π π§ =0.707, sin π π§ =β0.707 Therefore π π§ = ATan2 β¦ = β (-45 deg) cos π π₯ =β0.707, sin π π₯ =0.707 Therefore π π₯ = ATan2 β¦ = (135 deg) So, Solution 1 (in degrees) is π π₯ =135, π π¦ =45 and π π§ =β45 If π π¦ = π π¦2 = then By a similar reasoning Solution 2 (in degrees) is π π₯ =β45, π π¦ =135 and π π§ =135 Unless we have external information about the correct π π¦ , this is the best we can do
15
Conclusions Extracting Euler angles from a Rotation matrix is possible IF: You limit those angle to a specific range (we used [-ο°, ο°], fairly common) You know exactly the order of the 3 axes for the rotation For each specific 3-axis order there is a different set of operations to extract the three angles. You must multiply the three rotations symbolically and determine the best approach. The general algorithm is the same, but which entries to use will vary. At best there are still two possible solutions for each given rotation matrix (infinite if there is a gimble lock). Computing the angles rely heavily on using the ATan2 function This lecture is heavily inspired from βComputing Euler angles from a rotation matrixβ by G. G. Slabaugh. I recommend reading it!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.