# Rotation Matrix to Quaternion(proper Orientation)

Given Data in the figure

1. In this figure we have a unit vectors $x,y,z$ as axis. Axis of rotation is $b$ and angle of rotation is $\phi$. $\phi$ is unknown and $b$ is given as $b= \frac{1}{2 \sin(\phi)} \begin{bmatrix} R(3,2)-R(2,3) \\ R(1,3)-R(3,1) \\ R(2,1)-R(1,2) \end{bmatrix}$( reference link). We are given a rotation matrix with constant values , called ${R}_{3 \times 3}$. Then it is observed that we got $d_1,d_2,d_3$ from $x,y,z$ by applying $R$. Observe the rotation direction of $\phi$ around $b$, it is anti-clock wise direction
2. If I try to find the quaternion for $R$, I get the following,

Angle $\phi = \arccos\left( \frac{\mathrm{trace}(R ) - 1}{2} \right)$,$\phi$ can be +ve or negative. So it will affect $q=\cos(\phi/2)+b\sin(\phi/2)$ on "$\sin(\phi/2)$" part. And will give two solutions for q. Let us call it $q_1$ and $q_2$. We are sure one of them is clock wise rotation and other is anti-clock wise,but we are not sure which one is clock/anti clock wise

Question

1. If I require only the quaternion corresponding to anti-clock wise rotation from $q_1$ and $q_2$, is there any way to filter it out? In other words how can I identify the quaternion corresponds to the direction of rotation mentioned in the figure? More simply which one among $q_1$ and $q_2$ represnts anti-clock wise quaternion and how do we identify it

2. If I make a statement " A rotation matrix can have two quaternions represnting them, but a quaternion can have only one rotation matrix representing them" . Am I correct? If not why?

Thanks for taking time to read it

NB : I had posted some different problems arising from this same issue. I didnt get an answer. Please avoid posting any other links not related this problem.

I have the same questions that you, I did some search and I found a paper that discusses this issue: "A recipe on the parameterization of rotation matrices for non-linear optimization using quaternions" by Terzakis et al. According to it (for your first question):

Let $q_R(R):\mathbb{SO}(3)\to\mathbb{H}$ be such that:

$$q_R(R) = \begin{cases} q_R^{(0)}(R)\,\,\, \text{ if, }\, r_{22}>-r_{33} ,\, r_{11}>-r_{22},\,\,r_{11}>-r_{33},\\ q_R^{(1)}(R)\,\,\, \text{ if, }\, r_{22}<-r_{33} ,\, r_{11}>r_{22},\,\,r_{11}>r_{33},\\ q_R^{(2)}(R)\,\,\, \text{ if, }\, r_{22}>r_{33} ,\, r_{11}<r_{22},\,\,r_{11}<-r_{33},\\ q_R^{(3)}(R)\,\,\, \text{ if, }\, r_{22}<r_{33} ,\, r_{11}<-r_{22},\,\,r_{11}<r_{33}. \end{cases}$$ Where

$$q_R^{(0)}(R)=\frac{1}{2} \begin{bmatrix}\sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{32}-r_{23})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{13}-r_{31})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{21}-r_{12})/\sqrt{1+r_{11}+r_{22}+r_{33}} \end{bmatrix},$$

$$q_R^{(1)}(R)=\frac{1}{2} \begin{bmatrix}(r_{32}-r_{23})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\\sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{21}+r_{12})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{13}+r_{31})/\sqrt{1+r_{11}+r_{22}+r_{33}} \end{bmatrix}$$

$$q_R^{(2)}(R)=\frac{1}{2} \begin{bmatrix}(r_{13}-r_{31})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{21}+r_{12})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\ \sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{32}-r_{23})/\sqrt{1+r_{11}+r_{22}+r_{33}} \end{bmatrix},$$

and

$$q_R^{(3)}(R)=\frac{1}{2} \begin{bmatrix}(r_{21}-r_{12})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{13}+r_{31})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\(r_{32}+r_{23})/\sqrt{1+r_{11}+r_{22}+r_{33}}\\ \sqrt{1+r_{11}+r_{22}+r_{33}} \end{bmatrix}.$$

As for the second question, it seems that you are right, but I haven't found a counterexample. I hope that this helps.