Search code examples
accelerometergame-physicsandroid-sensors

Finding sign of acceleration


How can one find if device is accelerating or decelerating from 3-axis accelerometer? sqrt(x^2+y^2+z^2) will give magnitude of acceleration, but to find if it is acceleration or deceleration I guess some vector math has to be done. If anyone could direct me or link me with some source, that would be nice


Solution

  • I think there is no perfect solution to your problem: a decelleration is an acc with direction opposing the actual speed, and you have no (good) way to access the speed of the device.

    just to give you some ideas: you could keep an array of the last N values (as vectors (x y z)) of acc(t). If you move the accellerometer in some direction and then stop, I'd expect to have in that array something like { A1 A2 A3 A4 D1, D2, D3, D4 } where all the A are vectors more or less in the choosen direction (magnitude will vary) and all the D are vectors in the opposite of the choosen direction. The dot products of two A vectors would be positive, as of two D vectors, but dot product Ax*Dy will be negative and this should give you an hint of "the accellerometer is stopping"...

    another thing to note: in my experience the accellerometer data varies a lot, therefore it is usually best to calculate the "moving average" of those values and work with those