从CMRotationMatrix获取俯仰,偏航,滚动

我有一个CMRotationMatrix *腐,我想从matrix中得到音调,偏航,滚动。 任何想法我怎么能做到这一点?

谢谢

它更好地使用四元数比欧拉angular….滚动,俯仰和偏航值可以从四元数派生使用这些公式:

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是一个预处理指令,其实现方式如下:

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

这样做是为了将公式给出的弧度值转换成度。

有关转换的更多信息可以在这里find: tinkerforge和这里: 四元数和欧拉angular之间的转换 。

俯仰,偏航,从matrix滚动。 任何想法我怎么能做到这一点?

在哪个顺序? 俯仰,偏航和滚转,通常称为欧拉angular,并不代表旋转。 根据您执行单个子旋转的顺序,您将得到完全不同的旋转matrix。

我个人的build议:不要使用欧拉angular,他们只是要求(数值)麻烦。 使用matrix(你已经做了)或四元数。

自己find了:

 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; }