Get feed, dig, roll with CMRotationMatrix

I have CMRotationMatrix * rot, and I would like to get feed, yaw, roll from the matrix. Any ideas how I could do this?

thanks

+7
source share
3 answers

It is better to use a quaternion than Euler angles .... Roll, pitch and yaw values ​​can be obtained from a quaternion using the following formulas:

roll = atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z) pitch = atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z) yaw = asin(2*x*y + 2*z*w) 

It can be implemented as:

 CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion; myRoll = radiansToDegrees(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z)) ; myPitch = radiansToDegrees(atan2(2*(quat.x*quat.w + quat.y*quat.z), 1 - 2*quat.x*quat.x - 2*quat.z*quat.z)); myYaw = radiansToDegrees(asin(2*quat.x*quat.y + 2*quat.w*quat.z)); 

where radianstoDegrees is a preprocessor directive implemented as:

 #define radiansToDegrees(x) (180/M_PI)*x 

This is done to convert the radians given by the formulas to degrees.

More information on conversion can be found here: tinkerforge and here: Conversion between quaternions and Euler angles .

+22
source

pitch, yaw, roll of matrix. Any ideas how I could do this?

In what order? Pitch, yaw and roll, commonly referred to as Euler angles, do not represent rotation unambiguously. Depending on the execution order of the individual sub-turns, you get completely different rotation matrices.

My personal recommendations: do not use Euler angles at all, they just require (numerical) problems. Use a matrix (you already know) or a quaternion.

+1
source

Found myself:

 CMAttitude *currentAttitude = motionManager.deviceMotion.attitude; if (currentAttitude == nil) { NSLog(@"Could not get device orientation."); return; } else { float PI = 3.14159265; float yaw = currentAttitude.yaw * 180/PI; float pitch = currentAttitude.pitch * 180/PI; float roll = currentAttitude.roll * 180/PI; } 
-one
source

All Articles