Identity Quarternions (Bug)

If I try to convert an identity quaternion to a matrix4, I get an error. Matrix4 = NAN.

This is due to the axis being equal to 0,0,0 I believe.

```//  : IEquatable<Quaternion>
public bool Equals(Quaternion other)
{
return W == other.W
&& XZY.X == other.XYZ.X
&& XZY.Y == other.XYZ.Y
&& XZY.Y == other.XYZ.Z;
}

public static Matrix4 Rotate(Quaternion q)

{

if (q.Equals(Quaternion.Identity)) return Matrix4.Identity;

Vector3 axis;
float angle;
q.ToAxisAngle(out axis, out angle);
return Rotate(axis, angle);

}```

Comment viewing options

Re: Identity Quarternions

actually I think the bug is in the Quaternion ToAxisAngle function. It's not returning a normalised axis when the quaternion is the identity.

Mr Fiddler: could you update the function in question to read

```		public void ToAxisAngle(out Vector3 axis, out float angle)
{
Quaternion q = this;
if (q.W > 1.0f)
q.Normalize();

angle = 2.0f * (float)Math.Acos(q.W);
float den = (float)Math.Sqrt(1.0 - q.W * q.W);
if (den > 0.0001f)
{
axis = q.XYZ / den;
}
else
{
axis = Vector3.UnitX;
}
}```

Re: Identity Quarternions

That makes sense also. I was not sure how the ToAxis was supposed to behave in the case of Quaternion.Identity.

Thanks.

Re: Identity Quarternions

Fiddler, can you let us know what your thinking on this issue?