Search code examples
androidandroid-sensors

pitch value is -90 degree to 90 degree when reading orientation from android


I am reading the orientation values of the phone, the azimuth and roll data are quite OK as they are -180 to 180, but I have problem on pitch as it is -90 to 90 only when I rotate the phone from 0 degree to 360 degree.

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;

Could anyone help. Thanks


Solution

  • That strikes me as normal. If you think about it, pitch is essentially latitude in device coordinates, and latitude can't have a magnitude greater than 90 degrees - at that point (aka the north & south poles), it wraps around and begins to decrease again.