title: Converting CSS Matrix3d Transform into Euler Angles
body: <p>I'm unsure if this is possible, given that the order rotations are applied can affect the form of the rotational matrix; but I'd like get the Euler angles from a CSS matrix3d Transform. I'm finding a dearth of documentation on the format of the matrix3d and how transformations are applied. Here's my code so far:</p>
  
  <pre><code>getRotation: function (el) {
      var matrix = Esprit.getTransform(el);
      // 2d matrix
      if (matrix.length === 6) {
          return {
              x: 0,
              y: 0,
              z: Math.round(Math.atan2(matrix[1], matrix[0]) * (180 / Math.PI))
          };
      }
      // 3d matrix
      else {
          // incorrect calculations
          // only work for a single rotation
          // return {
          //      x: Math.round(Math.atan2(matrix[6], matrix[5]) * (180/Math.PI)),
          //      y: Math.round(Math.atan2(-matrix[2], matrix[0]) * (180/Math.PI)),
          //      z: Math.round(Math.atan2(matrix[1], matrix[0]) * (180/Math.PI))
          // };
  
          // convert from string to number
          // for (var i = 0, len = matrix.length; i &lt; len; i++) {
          //      matrix[i] = Number(matrix[i]);
          // }
  
          // gimball lock for positive 90 degrees
          if (matrix[2] === 1) {
              return {
                  x: Esprit.toDegrees(Math.atan2(matrix[0], matrix[1])),
                  y: Esprit.toDegrees(Math.PI / 2),
                  z: 0
              }
          }
          // gimball lock for negative 90 degrees
          else if (matrix[2] === -1) {
              return {
                  x: Esprit.toDegrees(-Math.atan2(matrix[0], matrix[1])),
                  y: Esprit.toDegrees(-Math.PI / 2),
                  z: 0
              }
          }
          // no gimball lock
          else {
              return {
                  x: Esprit.toDegrees(Math.atan2(matrix[6], matrix[10])),
                  y: Esprit.toDegrees(Math.asin(matrix[2])),
                  z: Esprit.toDegrees(Math.atan2(-matrix[1], matrix[0]))
              }
          }
  
      }
  },
  
  getTransform: function (el) {
      var transform = getComputedStyle(el).webkitTransform;
      return transform !== 'none' ? transform.split('(')[1].split(')')[0].split(',') : Esprit.create3dMatrix();
  },
  
  toDegrees: function (radians) {
      return Math.round(radians * 180 / Math.PI);
  }
  </code></pre>
  
  <p>Any help or ideas would be greatly appreciated. Thanks!</p>