How to rotate one vector about another?

Brief
Given 2 non-parallel vectors: a and b, is there any way by which I may rotate a about b such that b acts as the axis about which a is rotating?

Question
Given: vector a and b
To find: vector c where c is produced by rotating a about b by an angle θ clockwise given by right hand thumb rule.
Edit: There is a problem with the image! it was supposed to be rotated clockwise by right hand thumb rule unlike how it is shown in the image (but there shouldn't be much of a difference in the solution). Right hand thumb rule: "Wrap the fingers of your right hand around vector b such that your thumb points in the direction of vector b. Then, the direction of curvature of the rest of your fingers will indicate the direction a will be rotated about b"

• – BananaCats Category Theory App Oct 1 '13 at 18:35
• @reubenjohn: well, here you are! Welcome! I'll get to this in a little while, as promised . . . – Robert Lewis Oct 1 '13 at 18:37
• @reubenjohn: great picture, by the way. What's your graphics SW? – Robert Lewis Oct 1 '13 at 18:41
• @RobertLewis It was done in Google drive :) ... – reubenjohn Oct 1 '13 at 19:03
• @reubenjohn: really? thanks, I'll have to check that out! Thinking about your question . . . – Robert Lewis Oct 1 '13 at 19:04

Orthogonal component method:

$\vec a$ rotates about $\vec b$ in a clockwise direction by $\theta$ rad according to the right hand rule where your thumb represents $\vec b$, and the curling of your fingers represents the direction of the rotation. This method involves finding $\vec a_{\perp b}$, the component of $\vec a$ orthogonal to $\vec b$ and rotating it by $\theta$ along the plane with normal $\vec b$ .

$\vec a$ can be decomposed into two components:$$\vec a = \vec a_{\parallel \vec b} + \vec a_{\perp \vec b}$$

$\vec a_{\parallel \vec b}$ is the component of $\vec a$ in the direction of $\vec b$ $$\vec a_{\parallel \vec b} = \Big(\dfrac{\vec a\cdot \vec b}{\vec b\cdot \vec b} \Big)\vec b$$ $\vec a_{\perp b}$ is the component of $\vec a$ in the direction orthogonal to $\vec b$ 

\begin{align*} \vec a_{\perp \vec b} =& \vec a - \vec a_{\parallel \vec b} \\ \\\vec a_{\perp \vec b}=& \vec a - \Big(\dfrac{\vec a\cdot \vec b}{\vec b\cdot \vec b} \Big) \vec b \end{align*}

Our next step is to determine $\vec w = \vec b \times \vec a_{\perp \vec b}$

This vector orthogonal to both $\vec a_{\perp \vec b}$ and $\vec b$ .

Then we need to find a linear combination of $\vec a_{\perp \vec b}$ and $\vec w$ representing a rotation of $\vec a_{\perp \vec b}$

$$\vec a_{\perp \vec b, \theta} = ||\vec a_{\perp \vec b}||(x_1 \vec a_{\perp \vec b} + x_2 \vec w)$$

Where: $$x_1 = \dfrac{cos(\theta)}{||\vec a_{\perp \vec b}||}$$

and:

$$x_2 = \dfrac{sin(\theta)}{||\vec w||}$$

Finally we can make our vector representing the rotation of $\vec a$ around $\vec b$ by $\theta$ rad:

$$\vec a_{b,\theta} = \vec a_{\perp \vec b, \theta} + \vec a_{\parallel \vec b}$$

*NOTE:

1) As a preliminary belief check, make $(\theta = \pi/2$ ) or ( $\theta = 0$) and look at what the $sin(\theta)$ and $cos(\theta)$ in the equation for $\vec a_{\perp \vec b, \theta}$ do.*

2) If you need further demonstration that the last equation is the vector we are looking for just ask

3) The method described above is an adaptation of the "Rodrigues" rotation

Bibliography: "Linear Algebra with Applications" by Steven J. Leon https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula

• I implemented this in Python/Numpy. Thank you! gist.github.com/fasiha/… – Ahmed Fasih Dec 7 '16 at 4:06
• I'm happy you found it useful @Ahmed Fasih . Looks pretty neat in code. – MNKY Dec 9 '16 at 10:55
• ditto! Exactly what I needed and nicely explained. – uhoh Mar 18 '17 at 12:12

Roughly speaking you want to do this :

1. Start with $v_1 = b/|b|$ and extend it to an orthonormal basis $\{v_1, v_2, v_3\}$ of $\mathbb{R}^3$

2. Write these vectors as columns of a matrix $P$ (notice that $P$ is invertible)

3. Consider the matrix $B = PAP^{-1}$ where $$A = \begin{pmatrix} 1 & 0 & 0 \\ 0 & \cos(\theta) & -\sin(\theta) \\ 0 & \sin(\theta) & \cos(\theta) \end{pmatrix}$$

4. The vector you are looking for is $$c = B(a)$$

• By "Start with v1", did you mean "v" so that its orthonormal extension is {v1,v2,v3} – reubenjohn Oct 1 '13 at 19:35
• Also i have a doubt! From what I have understood from PAP-1, order of P will be [1x3], A is [3x3] and the product will be [1x3] which cant be multiplied with P-1 of order [1x3]. – reubenjohn Oct 1 '13 at 20:14
• No no! $P$ is a $3\times 3$ matrix - each column is a $1\times 3$ vector $v_i$ – Prahlad Vaidyanathan Oct 2 '13 at 3:04

A solution with quaternions:

Identify the quaternions with real part zero with vectors in $3$-space according to a Cartesian coordinate system: the $x$ axis becomes the coefficient for $i$, the $y$ axis for $j$ and the $z$ axis for $k$. In particular, we have quaternions $A=a_xi+a_yj+a_zk$ and $B=b_xi+b_yj+b_zk$ corresponding to the vectors $a=(a_x,a_y,a_z)$ and $b=(b_x,b_y,b_z)$.

Let $u$ be the quaternion $B$ normalized to unit length.

For your angle $\theta$ (measured in clockwise radians according to the right hand rule with $B$) compute $q=\cos(\theta/2)+u\sin(\theta/2)$.

The transformation $x\mapsto qxq^{-1}$ rotates the $3$-space of purely complex quaternions $\theta$ degrees clockwise around the axis presented by $u$ (which is the same as the axis $B$ gives). Keep in mind that $q^{-1}$ is just $\cos(\theta/2)-u\sin(\theta/2)$.

Notice that $qBq^{-1}=|B|quq^{-1}=|B|u=B$, showing that $B$ is the axis.

So to find out where $a$ is going, compute $qAq^{-1}$ and interpret the resulting quaternion as a vector in $3$-space.

• will qAq−1 produce a pure quaternion? if so what is the simplest way to compute it? (i would greatly appreciate it if a general formula for values of x, y and z of the resulting vector(pure quaternion) could be produced!...) – reubenjohn Oct 2 '13 at 14:55
• @reubenjohn Yes, it will produce a pure quaternion: it has to be, or else you couldn't interpret it as being in your $3$-space. It works because $q^{-1}=\overline{q}$. For any quaternion $A$ and unit length quaternion $q$, the real part of $qAq^{-1}$ is $(qA\overline {q}+\overline {qA \overline {q}})/2=(qA\overline {q}+\overline{\overline{q}}\overline{A}\overline{q})/2=q(\frac{A+\overline{A}}{2})\overline{q}=\frac{A+\overline{A}}{2}$ shows that $A$ and $qAq^{-1}$ have the same real parts. If $A$ was pure imaginary to begin with, then so is $qAq^{-1}$ – rschwieb Oct 2 '13 at 15:55
• @reubenjohn As for doing the computations, you can simply plug in your coordinates to the quaternions and multiply. I think it would be much more beneficial for your understanding if you handled this yourself, whether you choose to do computations by hand or by using quaternions in a program. Writing out complicated formulae is not a good use of my time, and blindly using them does not help you either. :) – rschwieb Oct 2 '13 at 16:02