# How do I multiple these matrices together?

As a personal brain exercise, I've recently been trying to work out the math involved with rotating vertices around an arbitrary axis in 3D space.

To do so, I've been relying very heavily on the following page:
http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/ArbitraryAxisRotation.html

Conceptually, I get everything, but now, I want to verify everything in the link above by doing the math necessary to work out the matrix that results from Txz-1, Tz-1, Rz(θ), Tz, Txz (please see section 5.1 in the link above).
The link above shows the matrices used for Txz, Tz and Rz(θ), and I was able to get the matrices required for Txz-1 and Tz-1 thanks to everyone's help here on this question:
How do I calculate the inverse of these matrices?

At this point, I have all five matrices I need, but I have to admit, as I start doing the matrix multiplication, things get way too hairy for me to handle real quick.
I have tried several times to first multiple Tx by Txz, then multiply the product of that by Rz(θ), and then multiple the product of that by Tz-1, and finally multiply the product of that by Txz-1, but I can't seem to get even remotely close to the matrix shown in section 5.1.

One technique I tried was substituting A for sqrt(u^2 + v^2) and B for sqrt(u^2 + v^2 + w^2), but even so, the math was too much for me to handle.

Could someone please offer me some advice for how to multiply these five matrices together so that I can confirm the result shown in section 5.1 in the link above?

Thank you very much.

There are simpler algorithms. Suppose the axis of rotation is defined as the vector from $\vec{v_{0}}$ to $\vec{v_{1}}$. Normalize this vector to a unit vector $\vec{u_{1}}$: $$\vec{u_{1}}=\frac{1}{|\vec{v_{1}}-\vec{v_{0}}|}(\vec{v_{1}}-\vec{v_{0}}).$$ Suppose $\vec{u_{1}}=(u_{1,1},u_{1,2},u_{1,3})$. You can easily find a unit vector $\vec{u_{2}}$ which is orthogonal to $\vec{u_{1}}$. For example, if $u_{1,1}=0$, then $\vec{u_{2}}=(1,0,0)$ works; otherwise $\vec{u_{2}}=\frac{1}{\sqrt{u_{1,1}^{2}+u_{1,2}^{2}}}(-u_{1,2},u_{1,1},0)$ works. Define the third vector as a cross-product in such a way that you end up with a right-hand triple: $$\vec{u_{3}}=\vec{u_{1}}\times\vec{u_{2}}.$$ A standard counter-clockwise rotation matrix $R(\theta)$ about the origin in the $x$-$y$ plane maps the unit vector $\hat{x}$ to $\cos\theta\; \hat{x}+\sin\theta \;\hat{y}$, and maps $\hat{y}$ to $-\sin\theta\;\hat{x}+\cos\theta\;\hat{y}$. A rotation matrix around $\vec{u_{1}}$ performs the following mappings: $$\vec{u_{2}} \mapsto\cos\theta\; \vec{u_{2}}+\sin\theta\;\vec{u_{3}} \\ \vec{u_{3}} \mapsto -\sin\theta\vec{u_{2}}+\cos\theta\vec{u_{3}}.$$
So, here's the final implementation of the transformation you want ($\cdot$ denotes dot product): \begin{align} R_{v_{0},v_{1}}(\theta)\vec{x} & = \left[(\vec{x}-\vec{v_{0}})\cdot\vec{u_{1}}\right]\vec{u_{1}} \\ & +\left[(\vec{x}-\vec{v_{0}})\cdot\vec{u_{2}}\right](\cos\theta\vec{u_{2}}+\sin\theta \vec{u_{3}}) \\ & +\left[(\vec{x}-\vec{v_{0}})\cdot\vec{u_{3}}\right](-\sin\theta\vec{u_{2}}+\cos\theta\vec{u_{3}})+\vec{v_{0}}. \end{align} This can be written as a matrix transformation using vector components $$\left[\begin{matrix} u_{1,1} & u_{2,1} & u_{3,1} \\ u_{1,2} & u_{2,2} & u_{3,2} \\ u_{1,3} & u_{2,3} & u_{3,3} \end{matrix}\right] \left[\begin{matrix} 1 & 0 & 0 \\ 0 & \cos\theta & -\sin\theta \\ 0 & \sin\theta & \cos\theta \end{matrix}\right] \left[\begin{matrix} u_{1,1} & u_{1,2} & u_{1,3} \\ u_{2,1} & u_{2,2} & u_{2,3} \\ u_{3,1} & u_{3,2} & u_{3,3} \end{matrix}\right] \left(\left[\begin{matrix}x_{1}\\x_{2}\\x_{3}\end{matrix}\right] -\left[\begin{matrix}v_{0,1}\\v_{0,2}\\v_{0,3}\end{matrix}\right]\right) + \left[\begin{matrix}v_{0,1}\\v_{0,2}\\v_{0,3}\end{matrix}\right]$$ You can easily add the fourth-dimension in order to absorb translation.
• I have given you the full description of a method. Have you compared the complexity of this with what you have referenced? Plus, what I have given you uses familiar $\mathbb{R}^{3}$ tools from calculus. In fact, you don't really need to use the matrices at the end at all. Just use the algorithm above it. Once you construct $\vec{u_{1}},\vec{u_{2}},\vec{u_{3}}$, everything else involves (a) vector addition/subtraction (b) scalar multiplication of a vector (c) dot product. The algorithm is simple enough that bothering with a final matrix form isn't critical. Apr 14, 2014 at 4:06