开发者

Tilt location iOS app

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 w开发者_如何转开发hat I'm trying to measure.


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜