Android SensorManager.getOrientation() returns pitch between -PI/2 and PI/2 -


i designing app needs check device's orientation (azimuth, pitch , roll). use following code achieve this:

@override public void onsensorchanged(sensorevent event) {     if(event.sensor.gettype() == sensor.type_accelerometer)         gravitymatrix = event.values.clone();// fill gravitymatrix accelerometer values     else if(event.sensor.gettype() == sensor.type_magnetic_field)         geomagneticmatrix = event.values.clone();// fill geomagneticmatrix magnetic-field sensor values     if(gravitymatrix != null && geomagneticmatrix != null){         rmatrix = new float[16];         imatrix = new float[16];          sensormanager.getrotationmatrix(rmatrix, imatrix, gravitymatrix, geomagneticmatrix);// retrieve rmatrix, necessary getorientation method         sensormanager.getorientation(rmatrix, orientation);// current orientation of device     } } 

now able azimuth, pitch , roll values 'orientation' float[]. goes fine azimuth , roll values (it returns correct angle), when print pitch value (orientation[1]), retrieve angle between pi/2 , -pi/2. don't understand why? unable retrieve angle greater pi/2 or less -pi/2. have angle of +- pi/2 , keep on rotating device (samsung galaxy s2) angle decreases after reached pi/2 value.

can explain me why pitch-angle behaving uncommon?

thanks in advance!

pitch calculated pitch = (float) math.asin(-rmatrix[7]); range of arcsin function [-pi/2, pi/2], asin can take value in between -pi/2 , pi/2.


Comments