# Apps How to combine accelerometer values into 1

Discussion in 'Android Development' started by rcasha, Nov 15, 2009.

1. ### rcasha Lurker Thread Starter Rank: None Points: 5 Posts: 2 Joined: Nov 15, 2009

Nov 15, 2009
2
0
5
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?

#1
2. ### metter Member Rank: None Points: 15 Posts: 33 Joined: Oct 19, 2009

Oct 19, 2009
33
0
15
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.

#2
3. ### DaveInNYC Member Rank: None Points: 16 Posts: 52 Joined: Nov 7, 2009

Nov 7, 2009
52
3
16
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.

#3
4. ### rcasha Lurker Thread Starter Rank: None Points: 5 Posts: 2 Joined: Nov 15, 2009

Nov 15, 2009
2
0
5
What I mean is: "How much is the phone being shaken - whether up and down, or sideways, or diagonally, etc?"

DaveInNYC: Thanks, that's what I needed.

#4
5. ### metter Member Rank: None Points: 15 Posts: 33 Joined: Oct 19, 2009

Oct 19, 2009
33
0
15
And that's exactly what I wrote. I just left you some thinking

#5