Hi, I found out that using Quaternion.Angle to compare 2 quaternions is much more inaccurate than anticipated. While for comparing floats typically a small epsilon would be sufficient, Quaternion.Angle delivers values such as 0.03 degrees for angles that are the same nearly 100%
Comparing 3 nearly identical angles (a,b,c) prints the following:
Angle a->c: 0[2,624672E-11]
Angle b->c: 0[8,443563E-14]
Angle a->b: 0,03956468[2,835323E-11]
where the first value is the result of Quaternion.Angle, while the number in the [ ] brackets is the sqared magnitude of the difference!
You can see that while a==b and b==c, a!=c by 0.04 degrees - which does not make sense (as it is a floating point accuracy error i would assume?)
Code for repro:
public class QuaternionBugRepro : MonoBehaviour
{
private void Awake()
{
var a = new Quaternion(-0.0821930915f, -0.685053766f, 0.32071647f, -0.648911834f);
var b = new Quaternion(0.082193099f, 0.685053766f, -0.32071647f, 0.648911774f);
var c = new Quaternion(0.0821931064f, 0.685053825f, -0.3207165f, 0.648911834f);
Debug.Log("Angle a->c: " + PrintDiff(a, c));
Debug.Log("Angle b->c: " + PrintDiff(b, c));
Debug.Log("Angle a->b: " + PrintDiff(a, b));
}
private string PrintDiff(Quaternion a, Quaternion b)
{
return Quaternion.Angle(a, b) + "[" + (a.Inverse() * b).eulerAngles.sqrMagnitude + "]";
}
}
Whats the best way to compare 2 quaternions, as apparently Quaternion.Angle is quite wrong?
Will you improve the accuracy of the Quaternion.Angle function?