CMAttitude 横滚和俯仰计算

发布于 2024-12-20 22:17:40 字数 301 浏览 3 评论 0原文

问题本身很简单。当使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小嗷兮 2024-12-27 22:17:40
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)); // PITCH !!!
myYaw = radiansToDegrees(asin(2*quat.x*quat.y + 2*quat.w*quat.z));
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)); // PITCH !!!
myYaw = radiansToDegrees(asin(2*quat.x*quat.y + 2*quat.w*quat.z));
谈情不如逗狗 2024-12-27 22:17:40

它可能是这样的:

roll = -atan(x / z);

尽管您需要根据您所在的方向更改符号,并且要小心 z=0 的渐近线。

我相信 Core Motion 实际上除了加速度计读数之外还使用陀螺仪测量来更准确地计算姿态(也许还可以处理 万向节锁)。

It's likely something like:

roll = -atan(x / z);

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).

万水千山粽是情ミ 2024-12-27 22:17:40
pitch = atan2(motion.gravity.z, motion.gravity.y)
roll = atan2(motion.gravity.z, motion.gravity.x)

这样,俯仰值将在 0 +pi 和 0 -pi 之间,就像滚动一样

pitch = atan2(motion.gravity.z, motion.gravity.y)
roll = atan2(motion.gravity.z, motion.gravity.x)

in this way the value of pitch it will be between 0 +pi and 0 -pi like roll

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文