How can i rotate a quaternion around its z-axis in order to make the x-axis point towards a certain (x,y)-point?

I have been able to calculate quaternions by rotating a unit vector [0,0,1] onto another unit vector, thus getting the direction along the z-axis i need. Now i would like to rotate that quaternion further to make its x-axis point (in the x-y plane) towards a given (x,y)-point.

I used Jur van den Berg's method from Calculate Rotation Matrix to align Vector A to Vector B in 3d?

I hope you can help, thank you!


1 Answer 1


The axis would be $[0,0,1]$.

The angle would be $\theta = \texttt{atan2}(y, x)$.

Then the quaternion would be $q = \left[ \cos\frac{\theta}{2}, \sin\frac{\theta}{2}[0,0,1]\right]$.

Or in your case $q = \left[ \cos\frac{\theta}{2}, 0, 0, \sin\frac{\theta}{2}\right]$


To use this to rotate another quaternion $r = [0, x, y, z]$, just use the following formula:

$$r_{rot} = qrq^{*}$$

Where $q^*= \left[ \cos\frac{\theta}{2}, 0, 0, -\sin\frac{\theta}{2}\right]$ is the conjugate of $q$ (i.e. the vector part is negated).

  • $\begingroup$ Thank you, i can calculate a quaternion about the z-axis with the x-axis pointing towards a given point. How can i use this to rotate an already existing quaternion about the z-axis? $\endgroup$
    – user102937
    May 2, 2017 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.