Solve for rotation quaternion that rotates $x$ into $y$. Given two quaternions $x$ and $y$ with $|x|=|y|$, their real part being zero (i.e. them being vectors) and knowing that $y$ resulted from a rotation of $x$ by unit quaternion $q$, i.e.
$$ y = q x q^{-1}, $$
is it possible to solve for $q$ in terms of $x$ and $y$.
I tried several kinds of multiplying from the left and from the right with $q$s, but non-commutative equation solving is rather unfamiliar and I cannot get the $q$ separated from both, $x$ and $y$.
 A: There is an infinite number of rotations that map a vector $\vec x$ onto another vector $\vec y$ with the same norm, one for every vector that lies on the angle bisector of $\vec x$ and $\vec y$. If we restrict them to the plane defined by $\vec x$ and $\vec y$, i.e., to an axis that’s perpendicular to both vectors, then in most cases there are only two possibilities, and we can always choose the one with rotation angle in the interval $[0,\pi]$.  
It’s convenient for the following to represent quaternions as ordered pairs $(r,\vec v)$ of a real number $r$ and vector $\vec v$. The product of two quaternions is then $$(r_1,\vec v_1)(r_2,\vec v_2) = (r_1r_2-\vec v_1\cdot\vec v_2,r_1\vec v_2+r_2\vec v_1+\vec v_1\times\vec v_2).\tag 1$$ As you probably know, rotating the vector $\vec v$ through an angle of $\theta$ about the axis given by the unit vector $\vec u$ can be accomplished by conjugating the pure quaternion $\mathbf v = (0,\vec v)$ by $$\mathbf q = \left(\cos{\frac\theta2},\vec u\sin{\frac\theta2}\right).\tag 2$$ Now, for a pair of pure quaternions, the product (1) reduces to $$(0,\vec x)(0,\vec y) = (-\vec x\cdot\vec y,\vec x\times\vec y) = \|\vec x\|\|\vec y\|(-\cos\theta,\vec u\sin\theta),$$ where $\theta$ is the angle between $\vec x$ and $\vec y$ and $\vec u = {\vec x\times\vec y\over\|\vec x\|\|\vec y\|}$ is the unit vector in the direction of $\vec x\times\vec y$. Comparing this to (2), we can see that constructing an appropriate rotation quaternion $\mathbf q$ from $\vec x$ and $\vec y$ is reduced to constructing a pair of vectors in the plane of $\vec x$ and $\vec y$ such that the angle between them is $\theta/2$. Taking $\vec x$ or $\vec y$ and their angle bisector $\vec x+\vec y$ will do the trick, resulting in $$\mathbf q = -\left(0,{\vec x+\vec y \over \|\vec x+\vec y\|}\right)\left(0,{\vec x \over \|\vec x\|}\right).$$ Note that this method fails when $\vec x=-\vec y$. In this case, $\mathbf q=(0,\vec u)$, where $\vec u$ is any unit vector orthogonal to $\vec x$.
