0

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 Answers1

0

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).$$

Ralff
  • 1,487
  • Yep, you're right. Had a lot of confusion about which norm is which. I've seen then 2-norm, Frobenius norm, Euclidean norm all used to describe "square root of the sum of the squares". I ended up using the 'Spectral norm' (also called the 2-norm in numpy documentation) which, I think, is the largest singular value of $A*A$.

    So is the L2 norm the spectral norm? And therefore am I looking for the largest singular value? And is the Frobenius norm the "square root of the sum of the squares" norm?

    And so does the L2 norm of LogR give theta?

    – Rory McDonald Feb 27 '20 at 15:41
  • Oh. I see your confusion. So, the Frobenius norm is equivalent to the element-wise 2 norm, and the spectral norm is equivalent to the induced 2-norm. You want to use the induced 2 norm to compute theta not the element wise 2 norm. Or, you can just use the equation I gave above instead of computing the log and the norm. – Ralff Feb 28 '20 at 17:11