[英]How to calculate g-force using x, y, z values from the accelerometer in Android 1.6
I can get the three x, y, and z values from the accelerometer in Android.我可以从 Android 中的加速度计获得三个 x、y 和 z 值。 How can I use these to calculate the g-force?
我如何使用这些来计算 g 力?
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
.如果加速度计以米每秒平方(SI 单位)为单位测量加速度,您可以通过除以
9.81
将每个加速度转换为g 力测量值。
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:如果要将 g 力作为无方向测量,只需将勾股定理应用于加速度的不同分量:
double g = Math.sqrt(x * x + y * y + z * z);
Just select TYPE_GRAVITY
instead of TYPE_ACCELEROMETER
as sensor type:只需 select
TYPE_GRAVITY
而不是TYPE_ACCELEROMETER
作为传感器类型:
https://developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-grav https://developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-grav
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.