倾斜定位 iOS 应用
如何确定 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该考虑使用 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)
加速度计就是您想要的。如果您的加速度矢量为
a = (x, y, z)
,则该矢量与三个轴之间的角度由下式给出:要获取角度本身,您需要使用反余弦功能。
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:To get the angles themselves you'll need to use the inverse cos function.