从CMRotationMatrix得到俯仰,偏航,滚动 [英] get pitch, yaw, roll from a CMRotationMatrix
问题描述
我有一个CMRotationMatrix * rot,我想从矩阵中得到俯仰,偏航,滚动。
任何想法我怎么做?
I have a CMRotationMatrix *rot and i would like to get the pitch, yaw, roll from the matrix. Any ideas how i could do that?
谢谢
推荐答案
使用四元数比使用欧拉角更好....滚动,俯仰和偏航值可以使用以下公式从四元数导出:
Its better to use the Quaternion than Euler angles.... The roll, pitch and yaw values can be derived from quaternion using these formulae:
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)
它可以实现为:
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));
其中radianstoDegrees是一个预处理器指令,实现如下:
where the radianstoDegrees is a preprocessor directive implemented as:
#define radiansToDegrees(x) (180/M_PI)*x
这样做是为了将公式给出的弧度值转换为度数。
This is done to convert the radian values given by the formulae, to degrees.
有关转换的更多信息,请访问:
tinkerforge 和此处:四元数和欧拉角之间的转换。
More information about the conversion can be found here: tinkerforge and here:Conversion between Quaternions and Euler angles.
这篇关于从CMRotationMatrix得到俯仰,偏航,滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!