Presentation is loading. Please wait.

Presentation is loading. Please wait.

GAM 325/425: Applied 3D Geometry

Similar presentations


Presentation on theme: "GAM 325/425: Applied 3D Geometry"β€” Presentation transcript:

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!

16


Download ppt "GAM 325/425: Applied 3D Geometry"

Similar presentations


Ads by Google