# Rotation matrix about an arbitrary axis

Tags:
1. Apr 6, 2015

### Happiness

Suppose a position vector v is rotated anticlockwise at an angle $\theta$ about an arbitrary axis pointing in the direction of a position vector p, what is the rotation matrix R such that Rv gives the position vector after the rotation?

Suppose p = $\begin{pmatrix}1\\1\\1\end{pmatrix}$ and $\theta$ = -120$^\circ$.

My approach is as follows.

First, perform transformation $T_1$: rotate the xy plane 45$^\circ$ anticlockwise about the z axis. (I treat this as keeping v fixed but expressing v in terms of the new coordinate system CS1.)

Next, perform transformation $T_2$: rotate the xz plane $\tan^{-1}\frac{1}{\sqrt2}$ clockwise about the y axis (clockwise when the y axis points into your eye) so that the x axis is now pointing in the direction of p. (Again, I treat this as keeping v fixed but expressing v in terms of the new coordinate system CS2.)

Then, perform transformation $T_3$: rotate the yz plane 120$^\circ$ anticlockwise about the x axis, since rotating v by -120$^\circ$ has the same effect as rotating the yz plane 120$^\circ$ (turning the coordinate system about the rotation axis by 120$^\circ$ while keeping v fixed).

We have $T_1=\begin{pmatrix}\frac{1}{\sqrt2}&\frac{1}{\sqrt2}&0\\-\frac{1}{\sqrt2}&\frac{1}{\sqrt2}&0\\0&0&1\end{pmatrix}$ , $T_2=\begin{pmatrix}\frac{\sqrt2}{\sqrt3}&0&-\frac{1}{\sqrt3}\\0&1&0\\\frac{1}{\sqrt3}&0&\frac{\sqrt2}{\sqrt3}\end{pmatrix}$ , $T_3=\begin{pmatrix}1&0&0\\0&-\frac{1}{2}&\frac{\sqrt3}{2}\\0&-\frac{\sqrt3}{2}&-\frac{1}{2}\end{pmatrix}$

Next, perform the inverse of transformation $T_2$. (Changing the expression of v from coordinate system CS2 back to CS1.)

Lastly, perform the inverse of transformation $T_1$. (Changing the expression of v from coordinate system CS1 back to CS0, the original coordinate system.)

Thus, R = $T_1^{-1}T_2^{-1}T_3T_2T_1 = \begin{pmatrix}0&0&-1\\1&0&0\\0&-1&0\end{pmatrix}$

But R should be $\begin{pmatrix}0&1&0\\0&0&1\\1&0&0\end{pmatrix}$ since rotating v about p by -120$^\circ$ has the effect of turning the x axis to the y axis, and the y axis to the z axis, and the z axis to the x axis (turning the coordinate system about the rotation axis p by 120$^\circ$ while keeping v fixed).

Why do I get different answers? What's wrong with my approach?

Last edited: Apr 6, 2015
2. Apr 7, 2015

### Happiness

Thanks for reading! The mistake has been found. $T_2$'s entries are wrong.

3. Apr 7, 2015

### HallsofIvy

Here is how I would do this, in general, to find the matrix that rotates a vector through angle $\theta$ about axis <a, b, c>. (I will assume that <a, b, c> has length 1: $\sqrt{a^2+ b^2+ c^2}= 1$.)

First, find the matrix that rotates < a, b, c> into < 0, 0, 1>. To do that, first find the matrix, A, that rotates, around the z-axis, mapping <a, b c> to <0, r, c> where $r= \sqrt{a^2+ b^2}$. I presume you know that, in two dimensions, the matrix rotating thorough angle $\theta$ is given by
$$\begin{bmatrix}cos(\theta) & - sin(\theta) \\ sin(\theta) & cos(\theta) \end{bmatrix}$$.

So we can write a rotating about the z-axis, as
$$\begin{bmatrix}\alpha & \ -beta & 0 \\ \beta & \alpha & 0 \\ 0 & 0 & 1\end{bmatrix}$$
so that such a matrix mapping <a, b, c> to < 0, r, c> must give
$$\begin{bmatrix}\alpha & \ -beta & 0 \\ \beta & \alpha & 0 \\ 0 & 0 & 1\end{bmatrix}\begin{bmatrix}a \\ b \\ c\end{bmatrix}= \begin{bmatrix}a\alpha- b\beta \\ a\beta+ b\alpha \\ c\end{bmatrix}= \begin{bmatrix} 0 // r // z\end{bmatrix}$$
That gives the two equations $a\alpha- b\beta= 0$, $a\beta+ b\alpha= r$.

If we multiply the first of those equations by a, to get $a^2\alpha- ab\beta= 0$, multiply the second equation by b, to get $b^2\alpha+ ab\beta= br$, then add the two equations, we eliminate b getting $(a^2+ b^2)\alpha= br$ so that $\alpha= \frac{br}{a^2+ b^2}= \frac{b}{r}$ since $r= \sqrt{a^2+ b^2}$. Putting that into $a^2\alpha- ab\beta= 0$ we get $ab\beta= a^2\alpha= \frac{a^2}{r}$ so that $\beta= \frac{a}{r}$.

That is, this matrix is
$$A= \begin{bmatrix}\frac{b}{r} & -\frac{a}{r} & 0 \\ \frac{a}{r} & \frac{b}{r} & 0 \\ 0 & 0 & 1\end{bmatrix}$$.

Now we want to find the matrix, B, that rotates, around the x-axis, mapping < 0, r, c> to < 0, 0 , 1>. We can write that as
$$\begin{bmatrix}1 & 0 & 0 \\ 0 & \alpha & -beta \\ 0 & \beta & \alpha \end{bmatrix}\begin{bmatrix} 0 & r & c \end{bmatrix}= \begin{bmatrix} 0 \\ r\alpha- c\beta \\ r\beta+ c\alpha \end{bmatrix}= \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}$$.

So we have the two equations $r\alpha- c \beta= 0$ and $c\alpha+ r\beta= 1$. Multiply the first equation by r, to get $r^2\alpha- rc\beta= 0$, multiply the second equation by c to get $c^2\alpha + rc\beta= c$, then add, eliminating $\beta$ and getting $(r^2+ c^2)\alpha= c$ so that $\alpha= \frac{c}{r^2+ c^2}= c$ since $\sqrt{r ^2+ c^2}= \sqrt{a^2+ b^2+ c^2}= 1$. Putting that into $r\alpha- c\beta= 0$ we have $$\beta= \frac{r}{c}(c)= r$$.

That is, this is the matrix
$$B= \begin{bmatrix}1 & 0 & 0 \\ 0 & c & -r \\ 0 & r & 1\end {bmatrix}$$

Now, to rotate a vector through angle $\theta$ about the vector <a, b, c>, multiply by A and B to rotate <a, b, c> into <0, 0, 1> then rotate through angle $\theta$ around the z-axis, then multiply by $B^{-1}$ and $A^{-1}$ to return to the original axis of rotation.

Last edited by a moderator: Apr 7, 2015