code: public static Vector3d transform(final Quat4d quat4d) {
          Vector3d result = new Vector3d();
  
          double test = quat4d.x * quat4d.z + quat4d.y * quat4d.w;
          if (test >= 0.5) { // singularity at north pole
              result.x = 0;
              result.y = Math.PI / 2;
              result.z = 2 * Math.atan2(quat4d.x, quat4d.w);
              return result;
          }
          if (test <= -0.5) { // singularity at south pole
              result.x = 0;
              result.y = -Math.PI / 2;
              result.z = -2 * Math.atan2(quat4d.x, quat4d.w);
              return result;
          }
          double sqx = quat4d.x * quat4d.x;
          double sqz = quat4d.y * quat4d.y;
          double sqy = quat4d.z * quat4d.z;
  
          result.x = Math.atan2(2 * quat4d.x * quat4d.w - 2 * quat4d.z * quat4d.y, 1 - 2 * sqx - 2 * sqz);
          result.y = Math.asin(2 * test);
          result.z = Math.atan2(2 * quat4d.z * quat4d.w - 2 * quat4d.x * quat4d.y, 1 - 2 * sqy - 2 * sqz);
          return result;
      }
docs: Conversion from quaternion to Euler rotation.
  The x value fr
  
  @param quat4d the quaternion from which the euler rotation is computed.
  
  @return a vector with the mapping: x = roll, y = pitch, z = yaw