How to combine accelerometer values into 1

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

  1. rcasha

    rcasha New Member
    5

    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?
     

    Advertisement
  2. metter

    metter Active Member
    15

    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.
     
  3. DaveInNYC

    DaveInNYC Well-Known Member
    16

    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.
     
  4. rcasha

    rcasha New Member
    5

    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.
     
  5. metter

    metter Active Member
    15

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

Share This Page

Loading...