setAxisAngleFromQuaternion method

Vector4 setAxisAngleFromQuaternion(
  1. Quaternion q
)

Implementation

Vector4 setAxisAngleFromQuaternion(Quaternion q) {
  // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm

  // q is assumed to be normalized

  w = 2 * Math.acos(q.w);

  var s = Math.sqrt(1 - q.w * q.w);

  if (s < 0.0001) {
    x = 1;
    y = 0;
    z = 0;
  } else {
    x = q.x / s;
    y = q.y / s;
    z = q.z / s;
  }

  return this;
}