开发者

How to calculate g-force using x, y, z values from the accelerometer in Android 1.6

开发者 https://www.devze.com 2023-03-11 21:28 出处:网络
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 sq

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号