Quote:
Originally Posted by NiMa
When it comes to forward/backward acceleration..
Can I "turn off" the two of the three axis of the accelerometer and only get data from the third, the horizontal one (is that x anyway?) so that there is no interference with the other accelerations?
For example if I keep the iphone in my pocket and start moving forward, can I get accurate data in regards to forward acceleration of my moving leg, regardless of how the iPhone is lying in my pocket( screen facingforward/backward, tilted to the left a bit.. slightly moving while my leg is moving forward..etc..)??
|
The answer to this question is a physics answer as well as a programming answer.
You can ignore 2 of the 3 axes of the accelerometer data, but that would yield invalid results.
Total acceleration is a vector in 3 axes. The only way you'd get correct data is if the phone was oriented precisely along the axis of the acceleration, which is very unlikely.
Instead, you should probably calculate the total magnitude of the acceleration:
Code:
total_acc = sqrt(x_acc*x_acc + y_acc*y_acc + z_acc*z_acc);
As somebody pointed out in another thread, that approach would return a constant value if the phone was rotating in a circle. You could use the magnitude combined with the direction of the acceleration (in 3 dimensions you'd get 2 angles, 1 for the x/y plane, and one for the z plane.)