code: public static final double[] getXYZEuler(Matrix m){
  		double heading, attitude, bank;
  
  		// Assuming the angles are in radians.
  		if (m.get(1,0) > 0.998) { // singularity at north pole
  			heading = Math.atan2(m.get(0,2),m.get(2,2));
  			attitude = Math.PI/2;
  			bank = 0;
  
  		} else if  (m.get(1,0) < -0.998) { // singularity at south pole
  			heading = Math.atan2(m.get(0,2),m.get(2,2));
  			attitude = -Math.PI/2;
  			bank = 0;
  
  		} else {
  			heading = Math.atan2(-m.get(2,0),m.get(0,0));
  			bank = Math.atan2(-m.get(1,2),m.get(1,1));
  			attitude = Math.asin(m.get(1,0));
  		}
  		return new double[] { heading, attitude, bank };
  	}
docs: Convert a rotation Matrix to Euler angles. This conversion uses
  conventions as described on page:
  http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm
  Coordinate System: right hand Positive angle: right hand Order of euler
  angles: heading first, then attitude, then bank
  
  @param m
  the rotation matrix
  @return a array of three doubles containing the three euler angles in
  radians