I am trying to understand rotations, and I need to understand what it takes to rotate vectors from a certain position on the unit sphere to another.
Let's say I am on $p=e_x$ and I want to go to $p'=\frac{1}{\sqrt{3}}(e_x + e_y + e_z)$.
If I want to go from $e_x$ to $e_x + e_y$, I can set up the unit vector $u = e_z$, and the quaternion $q_1 = \cos (\pi/8) + \sin (\pi/8) (0 i + 0j + 1k)$ and perform $p'' = q_1pq_1'$ where $p'' = 0 + 1/\sqrt{2}i+1/\sqrt{2}j+0k$.
How do I go from $p''$ to $p'$? How does one solve this inverse problems of rotation, where I have to go from $(\theta_1, \phi _1)$ to $(\theta _2, \phi _2)$?
Any advice you have would be appreciated!
We want to rotate $p = e_x$ to $p' = \frac1{\sqrt 3}(e_x+e_y+e_z)$. If we're using quaternions, the most useful way to formulate this rotation is with the exponential function: $$ v \mapsto e^{\theta P/2}ve^{-\theta P/2}. $$ Here, $v$ is any vector represented as an imaginary quaternion, $\theta$ is the angle between $p$ and $p'$, and $P$ is a unit imaginary quaternion representing the plane containing $p, p'$. The components of $P$ are the components of $\frac{p\times p'}{|p\times p'|}$, i.e. the unit normal of the plane of $p,p'$. Since $P^2 = -1$, this works just like it does with complex numbers: $$ e^{\theta P/2} = \cos\theta/2 + P\sin\theta/2. $$ We could compute $\theta$ from $p\cdot p' = \cos\theta$, but alternatively we could use the half-angle formulas $$ \cos\theta/2 = \pm\sqrt{\frac12+\frac12p\cdot p'},\quad \sin\theta/2 = \pm\sqrt{\frac12-\frac12p\cdot p'}. $$ Since $0\leq\theta < \pi$ is the angle between $p,p'$ we always choose $+$ for both. Then $$ p\cdot p' = \frac1{\sqrt 3},\quad P = \frac1{\sqrt2}(-j + k), $$ so we see that the rotation quaternion is $$\begin{aligned} q &= e^{\theta P/2} = \sqrt{\frac{\sqrt3+1}{2\sqrt3}} + \sqrt{\frac{\sqrt3-1}{2\sqrt3}}\frac1{\sqrt2}(-j + k) \\ &= \sqrt{\frac{3+\sqrt3}6} + \sqrt{\frac{3-\sqrt3}6}\frac1{\sqrt2}(-j + k) \end{aligned}$$ with $e^{-\theta P/2} = \bar q$ (the conjugate of $q$). We can then confirm that $$\begin{aligned} qp\bar q &= \left[\sqrt{\frac{3+\sqrt3}6} + \sqrt{\frac{3-\sqrt3}6}\frac1{\sqrt2}(-j + k)\right]i\left[\sqrt{\frac{3+\sqrt3}6} + \sqrt{\frac{3-\sqrt3}6}\frac1{\sqrt2}(j - k)\right] \\ &= i\left[\sqrt{\frac{3+\sqrt3}6} + \sqrt{\frac{3-\sqrt3}6}\frac1{\sqrt2}(j - k)\right]^2 \\ &= i\left[\frac{3+\sqrt3}6 + 2\frac{\sqrt{(3+\sqrt3)(3-\sqrt3)}}6\frac1{\sqrt2}(j-k) - \frac{3-\sqrt3}6\right] \\ &= i\left[\frac1{\sqrt3} + \frac1{\sqrt3}(j-k)\right] \\ &= \frac1{\sqrt3}(i + j + k). \end{aligned}$$
In the same way, we can see that to go from $p'' = \frac1{\sqrt2}(j + k)$ to $p' = \frac1{\sqrt3}(i + j + k)$ we need $$ \cos\theta' = p''\cdot p' = \frac2{\sqrt 6},\quad P' = \frac1{\sqrt2}(j - k),\quad $$$$\begin{aligned} q' &= e^{\theta'P'/2} = \sqrt{\frac{\sqrt6+2}{2\sqrt6}} + \sqrt{\frac{\sqrt6-2}{2\sqrt6}}\frac1{\sqrt2}(j-k) \\ &= \sqrt{\frac{3+\sqrt6}6} + \sqrt{\frac{3-\sqrt6}6}\frac1{\sqrt2}(j-k), \end{aligned}$$ and of course we achieve this rotation by $v \mapsto q'v\bar q'$.