• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to combine accelerometer values into 1

rcasha

Lurker
I'm developing an application which measures the accelerometer values to indicate how much the phone is being shaken. At the moment I'm just using the Z value, which works if the phone is lying flat on its back.
Is there any formula to combine x + y + z in order to give the value irrespective of the orientation of the phone?
 
If you mean what I think you mean:

If only Z it's Z.
X+Z it's: VALxz^2=X^2+Z^2
X+Y+Z it's: VALxyz^2 = VALxz^2 + Y^2



Hope that helps. Cheers.
 
My answer is somewhat close to what Metter said, but if I understand your question correctly, you want to get the amount of acceleration irrespective of direction. If that is the case, the value you would be looking for is the root of the sum of the squares:

absolute value = sqrt(X^2 + Y^2 + Z^2);

See The Pythagorean Theorem for details.
 
Back
Top Bottom