How to calculate g-force using x, y, z values from the accelerometer in Android 1.6
I ca开发者_运维百科n get the three x, y, and z values from the accelerometer in Android. How can I use these to calculate the g-force?
If the accelerometer measures acceleration in meters per second squared (the SI unit), you can convert each acceleration into a g-force measurement by dividing by 9.81
.
If you want the g-force as an directionless measurement, you just need to apply the pythagorean theorem to the different components of the acceleration:
double g = Math.sqrt(x * x + y * y + z * z);
Just select TYPE_GRAVITY
instead of TYPE_ACCELEROMETER
as sensor type:
https://developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-grav
精彩评论