我一直在尝试使用 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 系统。这是我想念的吗?