CMAttitude 横滚和俯仰计算
问题本身很简单。当使用 CMDeviceMotion 运动时,它包含一个名为 Attitude 的 CMAttitude 类型的对象,其中包含滚动和俯仰。滚动和俯仰描述了对象绕 Y 轴和 X 轴的旋转。当 iPhone 放在桌子上且显示屏朝上时,横滚和俯仰均为 0。当绕 Y 或 X 轴旋转 iPhone 时,这些值会更新。
我想知道这些值是如何计算的。有一种方法可以根据设备当前的重力矢量计算滚动和俯仰。音高似乎是: pitch = -asin(motion.gravity.y) 但我不知道如何计算滚动。
感谢您的帮助
The question itself is simple. When using the CMDeviceMotion motion it contains an object named attitude of type CMAttitude which contains roll and pitch. Roll and pitch describe the rotation of the object around the Y and X axis. When the iPhone lies on a table with the display pointing up roll and pitch are both 0. When rotating the iPhone around Y or X axis these values get updated.
I want to know how these values are calculated.There is a way to calculate roll and pitch from the current gravity vector of the device. The pitch seems to be: pitch = -asin(motion.gravity.y) but I can not figure out how to calculate the roll.
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它可能是这样的:
尽管您需要根据您所在的方向更改符号,并且要小心 z=0 的渐近线。
我相信 Core Motion 实际上除了加速度计读数之外还使用陀螺仪测量来更准确地计算姿态(也许还可以处理 万向节锁)。
It's likely something like:
though you need to alter the sign depending on which orientation you're in, and be careful around the asymptotes where z=0.
I believe Core Motion in reality uses gyro measurements in addition to the accelerometer readings to calculate the attitude more accurately (and maybe also to deal with gimbal lock).
这样,俯仰值将在 0 +pi 和 0 -pi 之间,就像滚动一样
in this way the value of pitch it will be between 0 +pi and 0 -pi like roll