I want to compute the distance between two unit quaternions to know if the angle between them is too big, because I don't want to apply the rotation if the angle between the quaternions is higher than $\pi$.
I have a problem with quaternion of opposite sign. Between $Q_1 = (-0.33, 0.13, -0.93, 0.05)$ and $ Q_2 = (-0.37, 0.10, -0.92, 0.00)$ I compute a distance of $0.15$, but between $Q_1$ and $Q_3 = (0.37, -0.09, 0.92, -0.00)$ I've got $ 6.14 = 2\pi -0.15$. Both $Q_2$ and $Q_3$ represents the same orientation but with opposite sign. I wonder why I don't have the same result.
The calculations I have to compute the distance between $Q_1$ and $Q_2$ are :
(1)$$ QuatProjection = Q_1 \times Q_2^{-1} $$ where $\times$ is the Hamilton product and $Q_2^{-1}$ is the conjugate of $Q_2$.
(2)$$ angle = 2arctan \Bigl(\frac{||QuatProjection||}{qw}\Bigr) $$ with $qw$ the $lambda$ of the quaternion $QuatProjection = (qx, qy, qz, qw)$ and $||Q||$ the norm of $Q$
(3)$$ QuatProjection = QuatProjection.\frac{angle}{||QuatProjection||} $$ with $.$ the scalar multiplication with each members of the quaternion.
Finally,
(4)$$ distance = || QuatProjection || $$
It seems that if I use the absolute value of $qw$, I've got the correct result but I don't understand why. It might just be fortuitous.
Although, I don't understand the purpose of the (3) equation, the scalar multiplication. I will be really grateful if someone can help me with my problem.