Could someone explain why this formula for quantifying distance between Euler angles is giving me an answer higher than expected?

158 Views Asked by At

From this paper I'm trying to use a method for comparing the distance between two rotation matrices. I'm using Φ6(R1,R2) = ||$log(R_1R_2^T )$|| (left side, page 159). When I tried this in python the answer this is providing is off by *sqrt(2). Is that because I'm misinterpretting the notation, or doing something wrong in python?

    Python:
    r1 = R.from_euler('xyz', [0,0,0],degrees = True).as_matrix()
    r2 = R.from_euler('xyz', [0,0,90],degrees = True).as_matrix()

    print("r1")
    print(r1)
    print("r2")
    print(r2)

    angle_dif_mat = logm(np.matmul(r1,r2.transpose()))
    print("Angle dif")
    print(angle_dif_mat)

    print("norm")
    print(np.linalg.norm(angle_dif_mat))
    print("this = expected*sqrt(2)")
    print("expected = pi/2")

Output:

r1
[[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]
r2
[[ 2.22044605e-16 -1.00000000e+00  0.00000000e+00]
 [ 1.00000000e+00  2.22044605e-16  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  1.00000000e+00]]
Angle dif
[[-2.22044605e-16  1.57079633e+00  0.00000000e+00]
 [-1.57079633e+00 -2.22044605e-16  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]]
norm
2.2214414690791826
this = expected*sqrt(2)
expected = pi/2
1

There are 1 best solutions below

2
On

I suggest manually coding each of the steps. You should indeed get $\frac{\pi}{2}$. However, perhaps, you are using the Frobenius norm instead of the L2 norm e.g., $|| \log{\mathbf{R}}||_\text{F} = \sqrt{2} |\theta|$.

Essentially, you are considering the distance between rotations (in the same basis) say $\mathbf{P}$ and $\mathbf{Q}$. This means that you can think of the rotations as $\mathbf{P} = {}^B\mathbf{R}_A$ and $\mathbf{Q} = {}^C\mathbf{R}_A$ where ${}^j\mathbf{R}_i$ denotes the rotation from basis $i$ to basis $j$. Keep in mind that $\mathbf{R}^{-1} = \mathbf{R}^T$, so ${}^j\mathbf{R}_i = {}^i\mathbf{R}_j^{-1} = {}^i\mathbf{R}_j^{T}$.

Thus, when you compute $\mathbf{P} \mathbf{Q}^T$, you are computing ${}^B\mathbf{R}_C = {}^B\mathbf{R}_A {}^A\mathbf{R}_C = {}^B\mathbf{R}_A {}^C\mathbf{R}_A^{T}$, which is the rotation from basis $\mathbf{C}$ to basis $\mathbf{B}$.

Now, the formula you provide is the norm of the logarithm of a rotation matrix. This is based on mapping between $\text{SO}(3)$ and $\text{so}(3)$. This is also equivalent to the angle of rotation if the rotation is in axis-angle representation (which is a common distance metric for rotations). You can more simply just compute the angle of rotation directly from $\mathbf{P} \mathbf{Q}^T$ by

$$ \theta = \arccos{\left(\frac{\text{Tr}(\mathbf{P} \mathbf{Q}^T) - 1 }{2} \right)}.$$

If you would manually compute the logarithm, computing $\theta$ is a substep, so you don't need the logarithm for your purpose i.e., the logarithm (which requires $\theta$) is given by

$$ \log{\mathbf{R}} = \frac{\theta}{2\sin{\theta}} (\mathbf{R} - \mathbf{R}^T).$$