开发者

Confused about the terminology when using the orientation sensor in Android

I've written a small app that outputs the roll, pitch, and azimuth returned from the device's sensor. However, I'm having difficulty understanding the numbers it returns.

Imagine that the user is holding his smartphone in portrait mode with the screen directly in front of him (the pose someone would be using to snap a photograph). He then jams a pencil through the middle of the screen and rotates the device around that pencil. If I wanted to detect when the user rotated to exactly 90 degrees around that penci开发者_运维知识库l (relative to it's starting position), which should I be interested in: roll, pitch, or azimuth?

The answer would seem to be obvious after a little experimentation or reading the Google docs. However, all three numbers change at approximately the same rate during my tests, so I'm thoroughly confused.


Why not use the accelerometer instead?

I think that's a better solution for you, when you want to detect the rotation of the phone.

Using the accelerometer will give you this result:

When holding the phone as in your example, one of the x, y or z values will be either -9.82 or 9.82 depending which way you hold the phone. Let's say x is -9.82, and when it rotates the value will increase until it hits 0 and then y will start increase/decrease depending om the rotation. When y is either -9.82 or 9.82 you've rotated the phone 90 degrees, and if x goes from -9.82 to 9.82 you've rotated 180 degrees.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜