quaternion validation
Posted: Thu Feb 14, 2013 3:06 am
Hi Norbo,
I recently encountered a problem where an orientation quaternion had valid numbers and wasn't failing validation, but the range they used were enough to cause problems later downstream. For instance, I had this: {X:-3.273159E+17 Y:-4.664622E+34 Z:1.334513E-40 W:1}, causing the LengthSquared() to return float.Infinity causing other problems later when the quaternion is used or normalized. I was wondering if perhaps it you would agree that the Quaternion.Validate() should also check the .LengthSquared() for Infinity, NaN and Zero? Or perhaps an epsilon test? Both seem to be invalid states for a quaternion.
This is what I did, for instance,
Thanks,
I recently encountered a problem where an orientation quaternion had valid numbers and wasn't failing validation, but the range they used were enough to cause problems later downstream. For instance, I had this: {X:-3.273159E+17 Y:-4.664622E+34 Z:1.334513E-40 W:1}, causing the LengthSquared() to return float.Infinity causing other problems later when the quaternion is used or normalized. I was wondering if perhaps it you would agree that the Quaternion.Validate() should also check the .LengthSquared() for Infinity, NaN and Zero? Or perhaps an epsilon test? Both seem to be invalid states for a quaternion.
This is what I did, for instance,
Code: Select all
[Conditional("CHECKMATH")]
public static void Validate(this Quaternion q)
{
if (IsInvalid(q.W) || IsInvalid(q.X) || IsInvalid(q.Y) || IsInvalid(q.Z))
{
throw new NotFiniteNumberException("Invalid value.");
}
var len = q.LengthSquared();
if (float.IsInfinity(len) || float.IsNaN(len) || len < 0.00001f)
{
throw new NotFiniteNumberException("Invalid value.");
}
}