Rotation matrix along a custom axis

1.4k Views Asked by At

For a certain software that I'm developing, I need to create a rotation matrix for a custom axis, and being almost completely self-taught in math, I am trying to wrap my mind around it, yet failing horribly. This is the simple rotation matrix for rotation along Z axis: $$\begin{pmatrix} \cos\theta& -\sin\theta& 0\\ \sin\theta& \cos\theta& 0\\ 0& 0& 1 \end{pmatrix}$$ Can someone explain how to I modify this matrix for use with a custom axis, which is offset from the Z axis by n degrees (and on the YZ plane)? I went at this problem for 2 days now, and I still can't solve it, no matter how many times I read the wiki article about rotation matrices... Attaching a picture to help you visualize the problem. Thank you in advance.

enter image description here

1

There are 1 best solutions below

3
On

In general, the result of rotating a vector $\mathbf v$ about an axis $\mathbf k$ (expressed as a unit vector) by an angle $\theta$ is given by the Rodrigues rotation formula: $$ \mathbf v' = \mathbf v \cos\theta + (\mathbf k \times \mathbf v)\sin \theta + \mathbf k(\mathbf k \cdot \mathbf v)(1-\cos \theta).$$ In your case you have $\mathbf k = (0, \sin n, \cos n)$. To compute the rotation matrix, we can use the above formula to compute $\mathbf v'$ in the case of $\mathbf v$ being each of the standard basis vectors $\mathbf e_1=(1,0,0)$, $\mathbf e_2=(0,1,0)$, and $\mathbf e_3 =(0,0,1)$. Stacking these results side-by-side as column vectors will gives us the $3 \times 3$ rotation matrix. Explicitly,

$$\begin{bmatrix}\cos \theta &-\cos n\sin \theta &\sin n\sin \theta \\ \cos n\sin \theta & (1-\cos \theta)(\sin n)^2 + \cos\theta & (1-\cos \theta)\cos n\sin n \\ -\sin n\sin\theta & (1- \cos\theta)\cos n\sin n & (1-\cos\theta)(\cos n)^2 + \cos\theta \end{bmatrix}$$