I have a three.js quaternion and would like to get the axis and angle representation of it. Is this possible in three.js or do I have to do this:
export function getAxisAndAngelFromQuaternion(q: Quaternion) {
const axis = [0, 0, 0];
const angle = 2 * Math.acos(q.w);
if (1 - q.w * q.w < 0.000001) {
// test to avoid divide by zero, s is always positive due to sqrt
// if s close to zero then direction of axis not important
axis[0] = q.x;
axis[1] = q.y;
axis[2] = q.z;
} else {
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/
const s = Math.sqrt(1 - q.w * q.w);
axis[0] = q.x / s;
axis[1] = q.y / s;
axis[2] = q.z / s;
}
return { axis: new Vector3().fromArray(axis), angle };
}