# Converting quaternions to spherical angles

Consider a situation where a beam is shot at a cube C from an arbitrary position P. The cube detects the angle of incidence relative to its $x$ axis. The cube can be rotated and moved, and the orientation (rotation) of the cube is being tracked.

Below is an example in two dimensions. In the reference orientation, $C_\text{ref}$, the angle of incidence is $0°$. The cube is then moved to an arbitrary position and rotated with an arbitrary quaternion rotation $\mathbf{q}$. The measured angle of incidence is now $\gamma$. By subtracting the rotation angle $\beta$, the angle of incidence relative to the reference orientation is found to be $\alpha$. ($\alpha = \gamma - \beta$) In three dimensions, the same problem would also have an elevation angle. My question is this: how do I convert the (three-dimensional) rotation from quaternions $\mathbf{q}=(q_0,q_1,q_2,q_3)$ to spherical angles $(\theta,\phi)$?

## 1 Answer

Any rotation in three-dimensions can be represented as a rotation by an angle $\theta$ about an axis determined by a unit vector $\hat{n}=(n_1,n_2,n_3)$ -- that is three parameters and not two as the OP indicates. Such a rotation can be represented by $$\exp(\theta\ \sum_{j=1}^3 n_j \cdot T^j)\ ,$$ where $(T^1,T^2,T^3)$ are a basis in the fundamental (three) representation of $so(3)$ and are given by the matrices $(T_{i})_{jk}=\epsilon_{ijk}$. The connection with quaternions that I know makes use of the isomorphism of the (complex) Lie algebras $so(3)$ and $su(2)$. We just replace $\mathbf{T}$ with the corresponding generators in the fundamental (two) dimensional representation of $su(2)$. A basis for this Lie algebra are given in terms of the Pauli matrices. Using the identification $$T^j \longleftrightarrow i\sigma^j/2\ ,$$ one obtains $$\exp(\theta\ \sum_{j=1}^3n_j \tfrac{i\ \sigma^j}2)= \cos \tfrac{\theta}2 \mathbf{1} + i \sin \tfrac\theta2 \sum_{j=1}^3 n_j\ \sigma^j$$ where I have used a standard identity involving Pauli matrices. The right hand side is a quaternion, if you wish. Note that this is not a 1-1 map as group manifold of $SU(2)$ is a double cover of $SO(3)$.

• Thanks for the reply. This doesn't seem to be a conversion into spherical angles (azimuth and elevation), though. Could you please explain how to obtain the azimuth and elevation? – eiterorm Jul 20 '14 at 23:17
• Also, I didn't quite understand what you meant by "that is three parameters and not two as the OP indicates". Have I somehow indicated a two-dimensional vector? The two-dimensional situation was just a simplified example to prevent a cluttered illustration. – eiterorm Jul 20 '14 at 23:18
• The three parameters that parametrise a three-dimensional rotation are the angle $\theta$ and the two parameters that specify a unit vector $\hat{n}$. You should be able to work out the change of variables from this to azimuth and elevation. – suresh Jul 21 '14 at 0:21
• I'm still not sure how to do this. I could convert it via the roll, pitch and yaw angles, but this approach has issues for certain angles. I'm looking for a solution without such issues. Could you please help me? – eiterorm Jul 21 '14 at 8:18