# How to get relative rotation matrix from two orientation values in android?

Following http://www.codeproject.com/Articles/729759/Android-Sensor-Fusion-Tutorial , I get two orientation values. Then, I transform those values to rotation matrices R1, R2.

I think the relative rotation matrix is $$R_{12} = R_1*R_2^T.$$

I test one case using matlab calibration toolbox. The ground truth for $R_{12}$ is $$\begin{bmatrix} 0.9970 & -0.0715 & -0.0298\\ 0.0744 & 0.9909 & 0.1118\\ 0.0216 & -0.1137 & 0.9933\end{bmatrix}$$

The values I got from android are $$ori1 = [0.6268438, -0.07218649, -0.2109669]$$ $$rot1 = [0.78306764, 0.5850639, -0.21096313 \\ -0.58581793, 0.80777377, 0.06571868 \\ 0.20886011, 0.07212382, 0.9752824]$$

$$ori2 = [0.81628907, -0.09071748, -0.28214455];$$ $$rot2 = [0.6394706, 0.7256131, -0.2540925;\\ -0.717076, 0.6821133, 0.14325997; \\0.27727118, 0.0905931, 0.95651114];$$

testR12 = rot1*rot2' =

0.9789   -0.1927    0.0683
0.1948    0.9805   -0.0264
-0.0619    0.0391    0.9973


There are many coordinates and I am lost. How to get correct value? What's wrong with that? I have been stuck for a week because of this problem.

• It seems that the issue I asked is not an easy. I should see ap.isr.uc.pt/archive/17.pdf . Nov 26 '14 at 15:51

Your error might be due to the indices used. Nevertheless, it is always better to state the proper procedure to do it, so that you could find your error.

Let us assume that a 3D scene point $P$ is related to the normalized coordinates of the camera $i$ with the extrinsic parameters $P'_i=R_iP+T_i$ and similarly to camera $j$ with $P'_j=R_jP+T_j$. To find the relative pose we could simply use these two equations to go from the camera coordinates of view $i$ to the real scene and then to the second view $j$. We could then write:

$P=R_i^{-1}(P_i-T_i)$ (from camera $i$ to world)

$P'_j = R_j (R_i^{-1}(P_i-T_i)) +T_j$. (from world to camera $j$)

If we re-arrange:

$P'_j = R_{rel}P_i +T_{rel}$, where $R_{rel}=R_jR_i^{-1}$ and $T_{rel}=-R_{rel}T_i+T_j$.

where the subscript rel refers to "relative" and is what we seek to find. Keep in mind that, as rotations are orthogonal, $R_i^{-1}=R_i^T$. You can always compute relative orientations in similar manners.

Throughout the computation we used the convention that the transformation $J=[R|T]$ is a mapping from scene to the camera (the inverse is hence the vice versa). The final pose transforms a point in camera $i$ to camera $j$.

• Thank you, but if I take $R_{rel}$, it is also wrong result, because it is just transpose of $R_{12}$. Nov 26 '14 at 9:49
• But are you making sure that your coordinate systems are the same as well? Maybe rotations are with respect to another frame. I have no clue about this software. Why don't you write directly to the author? Nov 26 '14 at 12:05
• Yes, I think the coordinate systems are different. So I tried several times to transform coordinate, but failed. Okay, I will send an email to an author. Nov 26 '14 at 12:12