Identity Quarternions (Bug)
Posted Sunday, 29 June, 2008 - 04:44 by Kamujin in
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.
Shouldn't this return Matrix4.Identity instead?
// : 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);
}
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);
}




Comments
Jul 04
09:06:02Re: Identity Quarternions
posted by georgeactually 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
{
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;
}
}
Jul 13
15:55:46Re: Identity Quarternions
posted by KamujinThat makes sense also. I was not sure how the ToAxis was supposed to behave in the case of Quaternion.Identity.
Thanks.
Jul 13
03:10:14Re: Identity Quarternions
posted by KamujinFiddler, can you let us know what your thinking on this issue?