倾斜定位 iOS 应用

发布于 2024-11-17 21:58:19 字数 230 浏览 2 评论 0原文

如何确定 iOS 应用程序中 y 方向的倾斜位置?首先我尝试玩加速计。但即使 iPhone 没有倾斜,加速计值也会发生变化。然后我尝试摆弄陀螺仪。但它只能感知倾斜的速率,不能感知倾斜的位置。

这就是我想要做的具体事情:

如果你将 iPhone 横向放置在桌子上,并且主页按钮位于顶部。然后,您慢慢地继续翻转它,使显示屏现在朝下(您看到手机的背面),并且主页按钮仍然位于左侧。我正在尝试测量实现这一点所需的倾斜运动。

How can I determine the tilt location in the y direction on my iOS app? First I tried playing with the accelerometer. But the accelerometer values change even if the iPhone isn't tilting. Then I tried playing around with the gyroscope. But that only senses the rate of the tilt, not the position of the tilt.

Here is specifically what I am trying to do:

If you place an iPhone on a table in landscape position with the home button on the top. Then you slowly proceed to flip it in a manner such that the display is now facing down (you see the back of the phone) and the home button is still on the left. That tilt motion that is needed to do that is what I'm trying to measure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

花开雨落又逢春i 2024-11-24 21:58:19

您应该考虑使用 Core Motion API,因为它提供了可用作欧拉角、四元数或旋转速率的值。看看

加速计检测和精灵旋转

iPhone - 什么是陀螺仪测量?我可以获得所有轴上的绝对度数测量吗?

iPhone - 核心运动(相对旋转)

You should consider to use the Core Motion API because it provides the values ready to use as Euler angle, quaternion or rotation rate. Have a look at

Accelerometer detection and sprite rotation

iPhone - What does the gyroscope measures? Can I get an absolute degree measurement in all axis?

iphone - core motion (relative rotation)

写下不归期 2024-11-24 21:58:19

加速度计就是您想要的。如果您的加速度矢量为 a = (x, y, z),则该矢量与三个轴之间的角度由下式给出:

cos (angleXaxis) = x / sqrt(x^2 + y^2 + z^2)

cos (angleYaxis) = y / sqrt(x^2 + y^2 + z^2)

cos (angleZaxis) = z / sqrt(x^2 + y^2 + z^2)

要获取角度本身,您需要使用反余弦功能。

The accelerometer is what you want. If your acceleration vector is a = (x, y, z), then the angles between this vector and the three axes are given by:

cos (angleXaxis) = x / sqrt(x^2 + y^2 + z^2)

cos (angleYaxis) = y / sqrt(x^2 + y^2 + z^2)

cos (angleZaxis) = z / sqrt(x^2 + y^2 + z^2)

To get the angles themselves you'll need to use the inverse cos function.

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