# How to calculate the rotation matrix with respect to a given vector?

Suppose that I am given a vector $(a,b,c) \in R^3$, and I want to calculate the representation matrix of the rotation of $180$ degrees around this vector. My attempt is to geometrically find out the coordinate of the standard basis after rotation. Using dot product, I can find out the angle between $e_1 = (1,0,0)$ and $(a,b,c)$. Then suppose $e_1$ is rotated to $a_1$. I now have three equations for $a_1$, namely the angle between $a_1$ and $(a,b,c)$, then length of $a_1$ and $a_1-e_1$ is orthogonal to $(a,b,c)$. However this turns out to be hard to calculate, is there any simpler method?

In the general case, there's an axis-and-angle formula for rotation matrices.

In your particular case of rotating through $\pi$, though, there's a simpler solution.

To rotate a vector $x$, consider the components of the rotated vector $x'$ along $v=(a,b,c)$ and perpendicular to it. The parallel component is unchanged and the perpendicular component is reversed. Thus

$$x'=x_\parallel-x_\perp=\frac{vv^\top x}{v^\top v}-\left(x-\frac{vv^\top x}{v^\top v}\right)=2\frac{vv^\top x}{v^\top v}-x\;,$$

so the desired matrix is

$$2\frac{vv^\top}{v^\top v}-I\;.$$

• But shouldn't the first term be $2 \frac{v^Tx}{\sqrt{v^Tv}}x$? – Keith Mar 25 '16 at 14:35
• @Keith: No. Apart from normalisation problems, that's a vector along $x$; the parallel component is supposed to be the component of $x$ along $v$, not the component of $v$ along $x$. – joriki Mar 25 '16 at 14:40
• I see my problem, thanks. – Keith Mar 25 '16 at 14:43

Given the vector $\mathbf{v}=(a,b,c)^T$ you can normalize it to $$\mathbf{u}=\frac{\mathbf{v}}{|\mathbf{v}|}$$ than use a matrix to represent the rotation, as you can see here.

Another useful way to represent rotations in 3D is using quaternions. In such representation a rotation of an angle $2\theta$ in space, around an axis passing through the origin, is represented by a quaternion $e^{\mathbf{u}\theta}$, where $\mathbf{u}$ is the imaginary quaternion that correspond to the unit vector oriented along the axis of rotation. So we have the correspondence: $$\vec{w}=R_{\mathbf{u},\theta} \; \vec{v} \quad \longleftrightarrow \quad \mathbf{w}= e^{\mathbf{u}\theta/2}\mathbf{v}e^{-\mathbf{u}\theta/2}$$