有没有关于如何在 iPhone OS 中使用加速度计的好例子?
我认为地球重力存在一些问题,所以我想知道是否有任何例子可以说明加速度计通过减去这些问题来工作。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我认为地球重力存在一些问题,所以我想知道是否有任何例子可以说明加速度计通过减去这些问题来工作。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
(太糟糕了,您无法向地球提交错误来解决其重力问题!)
UIAcceleration 类参考。
正如该文档所述,值 1.0 大约代表 +1g。 因此,如果您将 iPhone 以纵向方向笔直向上,您应该会大致看到 <0, -1, 0>。 当您旋转手机时,加速度矢量
sqrt(x*x+y*y+z*z)
的大小应保持在 1 左右。(It's too bad you can't file a bug with planet Earth to fix its Gravity issue!)
There are several examples listed under "Related sample code" in the UIAcceleration Class Reference.
As that doc states, a value of 1.0 represents roughly +1g. So if you point the iPhone straight up in portrait orientation, you should see roughly <0, -1, 0>. As you rotate the phone around, the magnitude of the acceleration vector
sqrt(x*x+y*y+z*z)
should stay around 1.Apple 的 AccelerometerGraph 演示包含实现高通滤波器的示例代码 - 有效地滤除重力的影响。 获取它并进行修改以满足您的需求非常简单。
Apple's AccelerometerGraph demo includes sample code that implements a high-pass filter-- effectively filtering out the effect of gravity. It's pretty simple to just grab it and modify to suit your needs.