加速度计传感器返回设备的加速度。这是 3 维空间中的向量。该向量在设备坐标系中返回。你想要的是这个向量在世界坐标中的坐标,简单来说就是
R = rotation matrix obtained by calling getRotationMatrix
A_D = accelerator vector return by sensor ( A_D = event.values.clone )
A_W = R * A_D is the same acceleration vector in the world coordinate system.
A_W is an array of dimention 3
A_W[0] is acceleration due east.
A_W[1] is acceleration due north.
这是一些计算它的代码(假设gravity
并magnetic
包含来自各自传感器的输出):
float[] R = new float[9];
float[] I = new float[9];
SensorManager.getRotationMatrix(R, I, gravity, magnetic);
float [] A_D = values.clone();
float [] A_W = new float[3];
A_W[0] = R[0] * A_D[0] + R[1] * A_D[1] + R[2] * A_D[2];
A_W[1] = R[3] * A_D[0] + R[4] * A_D[1] + R[5] * A_D[2];
A_W[2] = R[6] * A_D[0] + R[7] * A_D[1] + R[8] * A_D[2];