I currently have two rotation vectors r1 and r2 using axis-angle representations, i.e. they are 3d vectors, their norms are the rotation angles and the normalized unit vectors are rotation axes respectively.
I am confused how to compare r1 and r2. In an optimization process of a regression system, if r1 is the ground truth, and r2 is the current result produced by the system, how do I define a proper loss to encourage the system to converge to r1? Can I just use L1/L2 loss between r1 and r2?
Thanks!
There are multiple ways one could define the error between two rotation, see for example: Huynh, Du Q. "Metrics for 3D rotations: Comparison and analysis." Journal of Mathematical Imaging and Vision 35.2 (2009): 155-164. That source mainly defines errors between rotation matrices and quaternions, but your representation can be converted to those relatively easily. In my opinion the most geometrically meaningful error measure would be the smallest angle the second rotation representation would have to be rotated by in order to match the first rotation. This angle can be calculated from the rotation separating the two, which can be obtained by first representing $r_1$ and $r_2$ as rotation matrices or quaternions and divide one by the other.
Your axis-angle representation can be converted into a rotation matrix using
$$ R(r) = I + \frac{\sin(\|r\|)}{\|r\|}S(r) + \frac{1-\cos(\|r\|)}{\|r\|^2}S(r)^2, \tag{1} $$
with $I$ the three by three identity matrix, $r = \begin{bmatrix}r_1 & r_2 & r_3\end{bmatrix}^\top$ the vector of the axis-angle representation and
$$ S(r) = \begin{bmatrix} 0 & -r_3 & r_2 \\ r_3 & 0 & -r_1 \\ -r_2 & r_1 & 0 \end{bmatrix}. \tag{2} $$
Rotation matrices can be "divided" by each other by multiplying one by the inverse of the other and the inverse of a rotation matrix is the same as the transpose of that rotation matrix. Taking the transpose of a matrix is equivalent to negating its skew-symmetric part. From $(1)$ it can be noted that $S(r)$ is always skew-symmetric, but $I$ and $S(r)^2$ are symmetric. Using this and that the scalar parts of $(1)$ are even or odd functions of $\|r\|$ yields that when taking the transpose of $(1)$ is equivalent to using $R(-r)$. Therefore, the relative rotation in your case could be obtained using
$$ R_e = R(r_1)\,R(-r_2), \tag{3} $$
whose associated angle in the interval $[0,\pi]$ can be calculated with
$$ \theta = \cos^{-1}\left(\frac{\text{tr}(R_e) - 1}{2}\right). \tag{4} $$
It is also possible to calculate the same using unit quaternions. The axis-angle representation can be converted into a quaternion using the scalar vector representation with
$$ q(r) = \left(\cos\left(\frac{\|r\|}{2}\right),\sin\left(\frac{\|r\|}{2}\right)\frac{r}{\|r\|}\right). \tag{5} $$
Quaternion can be divided by each other by multiplying one by the inverse of the other. Here the inverse of unit quaternions can be obtained by negating the vector part. However, when multiplying the quaternions together one has to use the Hamilton product. When one only want to recover the angle in the interval $[0,\pi]$ from the resulting unit quaternion it is sufficient to only calculate the scalar part. After substituting in $(5)$ it can be shown that the resulting angle can be calculated with
$$ \theta = 2\cos^{-1}\left(\left|\cos\left(\frac{\|r_1\|}{2}\right) \cos\left(\frac{\|r_2\|}{2}\right) + \sin\left(\frac{\|r_1\|}{2}\right)\sin\left(\frac{\|r_2\|}{2}\right)\frac{r_1^\top\,r_2}{\|r_1\|\,\|r_2\|}\right|\right). \tag{6} $$
Both $(4)$ and $(6)$ should give the same result (up to machine accuracy), but $(6)$ is probably faster to calculate.