BSNS102 Study Guide - Final Guide: Gimbal Lock, Atan2, Rotation Matrix

29 views4 pages

Document Summary

Now we can compute h from m31 and m11, which contain the sine and cosine of the heading, respectively. Let"s look at some code to extract the euler angles from an inertial-to-object rotation matrix using the technique developed above. To make the example simple, we will assume global vari- ables for input and output: Listing 10. 3: extracting euler angles from an inertial-to-object rotation matrix. // assume the matrix is stored in these variables: float m11,m12,m13; float m21,m22,m23; float m31,m32,m33; // we will compute the euler angle values in radians and store them here: float h,p,b; // extract pitch from m23, being careful for domain errors with asin(). // values slightly out of range due to floating point arithmetic. float sp = m23; if (sp <= 1. 0f) { p = 1. 570796f; // pi/2. } else if (sp >= 1. 0) { p = 1. 570796; // pi/2. // check for the gimbal lock case, giving a slight tolerance.