Here you can find the source of matrixToQuaternion(float[] m)
public static double[] matrixToQuaternion(float[] m)
//package com.java2s; public class Main { public static double[] matrixToQuaternion(float[] m) { double[] res = new double[4]; // w/*from w ww . j a va 2s.c o m*/ res[0] = Math.sqrt(1.0 + m[0] + m[5] + m[10]) / 2.0; double w4 = (4.0 * res[0]); res[1] = (m[9] - m[6]) / w4; // x res[2] = (m[2] - m[8]) / w4; // y res[3] = (m[4] - m[1]) / w4; // z return res; } }