Accelerometer data on the iPhone is presented in g-force units. The x axis is aligned with the top edge of the screen of your phone, the y axis is aligned with the left edge, and the z axis goes straight from the screen towards you if you look at it. Therefore, when your phone is standing on the table face up, you should get the values (0, 0, -1)
for the x, y and z axes, respectively. If you drop your phone while it is in free fall, you should receive (0, 0, 0)
.
Assuming you hold the phone the same as when moving to get three-dimensional acceleration in meters per second squared:
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration { float g = 9.80665f; float x = acceleration.x * g; float y = acceleration.y * g; float z = (acceleration.z + 1.0f) * g;
Please note that you must subtract the effect of Earth's gravity to get acceleration relative to your living room, and not relative to 4-dimensional space-time.
Also keep in mind that the iPhone’s accelerometer is quite noisy and these values tremble even when the phone is static, so you'll want to apply some anti-aliasing. However, if you use a similar technique for what you seem to be doing with the position data by placing the values in an array every frame to get a moving average over the last 0.5 seconds, this will smooth out the data for you.
Another thing to be aware of is that the iPhone’s accelerometer peaks around 2.3 g. These g-forces are not easy to achieve (for example, if you clap your hands) so that you can exceed them, and the methods that accumulate data will not be very reliable.
source share