从 Android 读取方向时,俯仰值为 -90 度到 90 度



我正在读取手机的方向值,方位角和滚动数据还可以,因为它们是-180到180,但是当我将手机从90度旋转到90度时,我在音高上遇到了问题-0到360。

SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
SensorManager.getOrientation(mRotationMatrix, orientationVals);
float azimuth = (float)Math.toDegrees(orientationVals[0]); 
float pitch = (float)Math.toDegrees(orientationVals[1]);
float roll = (float)Math.toDegrees(orientationVals[2]);
float deltaX = Math.abs(mLastOrientation[0] - azimuth);
float deltaY = Math.abs(mLastOrientation[1] - pitch);
float deltaZ = Math.abs(mLastOrientation[2] - roll);
if (deltaX < ORIENTATIONNOISE) azimuth = mLastOrientation[0];
if (deltaY < ORIENTATIONNOISE) pitch = mLastOrientation[1];
if (deltaZ < ORIENTATIONNOISE) roll = mLastOrientation[2];  
mLastOrientation[0] = azimuth;
mLastOrientation[1] = pitch;
mLastOrientation[2] = roll;

谁能帮忙。谢谢

这让我觉得很正常。如果你考虑一下,俯仰本质上是设备坐标中的纬度,纬度不能有大于 90 度的幅度——在这一点上(又名北极和南极),它会环绕并再次开始减小。

最新更新