I have a program which utilizes an accelerometer in the Windows Phone 7, and I need to detect what the rotation of the device is. I have X, Y, Z accelerations, and need to somehow figure out the orientation of the phone based off of that. How can this be accomplished? (Rotation values should be in Degrees)
-
I would like X, Y, and Z rotation values. To rotate around in a 3D scene (similar to a racing game). – bbosak Feb 05 '11 at 20:46
-
Are you trying to perform an action when the user rotates the phone? Or are you simply trying to find a way to programatically update the users "view" within your 3D scene? – Dave Feb 05 '11 at 21:24
-
Programatically update the view within the 3D scene. – bbosak Feb 05 '11 at 22:35
-
2Is there enough information in three linear accelerations to deduce three rotational velocities? In a system with *six* degrees of freedom you usually can't deduce three unknown parameters from three known parameters; that's what *six degrees of freedom* means. – Eric Lippert Feb 06 '11 at 15:22
-
I just need some way to rotate around a 3D scene (similar to a racing game) based off of the orientation of the device. – bbosak Feb 06 '11 at 17:03
3 Answers
Although I am working on iPhone it should basically the same problem. Your hardware needs a gyroscope sensor to describe rotations, especially those in parallel to gravity (let's call this z, x is right and y is up). If the device lays flat on the table and you rotate around this z-axis, there are only tiny accelerations measured resulting from centrifugal forces. So you can get some information about rotation, but you are limited in:
1) Users have to hold the device in specific manner for you to detect the rotation properly
2) Even if you got the best case of 45 degree to ground, it is very hard to get all 3 dimensions. You are better off, if you can limit detection on 2 rotational directions only.
3) You are limited to either rotations or translations, but combining detection of rotations with linear motions simultaneously is pretty hard.
Conclusion: For a racing game force users to hold the device in certain angle, limit on z-Rotation for steering wheel and some other direction for e.g. power slides or whatever.

- 12,918
- 4
- 55
- 77
Use of axis can be quite confusing. I stay with the orientation of X for horizontal axis (left and right), Y for vertical axis (up and down) and Z axis is the depth(far and near).
Using the accelerometer, you can only detect rotation about the X axis and Z axis, but not the Y axis.
Suppose your phone is place flat at rest position, the force of gravity will result in the Y acceleration to be around -9.8, and the X and Z acceleration will be around 0.
Assume that phone remains flat in the position. When you rotate the phone about the Y axis (assuming there is no translation to the phone or change in position to the phone as you rotate), there is no significant change to the value of X, Y and Z acceleration. Therefore, you can't detect any rotation about the Y axis.
When you rotate about X and Z axis (assuming no change in position of the phone while rotating), all the 3 acceleration values changes, but vectors will have the characteristic of x^2 + y^2 + z^2 = 9.8^2.
You can use simple trigonometrical formula to determine the rotation about the Z and Z axis.
As pointed out by Kay, you will still need the gyroscope to output the angular velocity of the rotation about each axis to compute the rotation about the y axis.

- 11
- 1
-
Which is fine, because as of just recently; the Gyroscope is now included in Windows Phone! – bbosak Aug 03 '11 at 21:08
If you want to get the rotation angle of the phone held in your hands (ie rotated in one plane) let's say held facing your chest...
atan2(y accel., x accel.)
You'll get rotational values :) It's likely to be jittery so you'll probably want to average the results over a sample period to smooth it out.

- 11
- 1