【发布时间】:2013-10-15 17:57:53
【问题描述】:
我一直在尝试使用 getOrientation() 方法获取航向值。
boolean success = SensorManager.getRotationMatrix(rot, incl, accel, magnet);
if (success) {
// Compute orientation
float orientation[] = new float[3];
SensorManager.getOrientation(rot, orientation);
}
即使我保持手机稳定并以稳定的位置行走,这些值也会有很大差异。
然后我尝试将加速度值的参考从手机更改为世界轴:
// Compute world acceleration
float wAccel[] = new float[4];
float newAccel[] = new float[]{accel[0],accel[1],accel[2], 0};
android.opengl.Matrix.multiplyMV(wAccel, 0, rot, 0, newAccel, 0);
magnetLine += "W" + LOGSEPARATOR +
tsString + LOGSEPARATOR +
wAccel[0] + LOGSEPARATOR +
wAccel[1] + LOGSEPARATOR +
wAccel[2] + "\n";
}
然后我在 atan2 函数上使用 X 和 Y 轴的值来确定向量的角度。即使以不同的方式变化,这些值仍然会表现出奇怪的行为(有时值是恒定的,有时会表现出周期性的行为,就像跟随脚步一样)。
我见过一些人调用 remapCoordinate system 来解决与此类似的情况。这是我想念的吗?
【问题讨论】:
标签: android orientation sensors