How to multiply matrices?

150 Views Asked by At

I've written a java-programm(JOGL) and have my vertices from the object I want to draw on screen. I've read, when I want to rotate my object I must multiply the matrix of my object with the so-called "rotation-matrix". Link -> rotationsmatrix . I don't know what I've done wrong by multiplying the two matrices. So please, can anyone help me?

1

There are 1 best solutions below

8
On BEST ANSWER

I cannot read German, but I used Google translate. Please forgive me if I've misunderstood your goal.

Your mistake was in your definition of the rotation matrix. Because you are rotating the object around the positive $z$ axis, the $z$ coordinate should not change after the rotation. The rotation matrix should be a $3\times3$ matrix, not a $4\times4$; the result should be a $3\times1$ column vector that describes a point, not a $4\times4$ matrix.

I will call $\vec M$ the original point vector and $\vec M'$ the rotated point vector.

Thus: $$\vec M' = \mathbf R \vec M$$

We let $\vec M = \pmatrix{x \\ y \\ z}$.

Because we are rotating around the positive $z$-axis, the rotation matrix is: $$R = \pmatrix{\cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1}$$

Thus: $$\begin{align} \vec M' &= \pmatrix{\cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1}\pmatrix{x \\ y \\ z} \\ &= \pmatrix{x\cos\theta -y\sin\theta \\ x\sin\theta + y\cos\theta \\ z} \end{align}$$