任何想法我怎么能这样做?
谢谢
解决方法 使用四元数比使用欧拉角更好….滚动,俯仰和偏航值可以使用以下公式从四元数导出: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
这样做是为了将公式给出的弧度值转换为度.
有关转换的更多信息,请访问:
tinkerforge和这里:Conversion between Quaternions and Euler angles.
以上是内存溢出为你收集整理的ios – 从CMRotationMatrix获得音高,偏航,滚动全部内容,希望文章能够帮你解决ios – 从CMRotationMatrix获得音高,偏航,滚动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)