Transformation Matrix for cube in 2D

1k Views Asked by At

My task is to transform the cube from the left corner to the big cube in the middle:

What I did was:

First i scale the cube:

$$ \begin{pmatrix} 4 & 0 & 0 \\ 0 & 4 & 0 \\ 0 & 0 & 1 \\ \end{pmatrix} $$

Next i rotate it $45^\circ$:

$$ \begin{pmatrix} \cos(45^\circ) & -\sin(45^\circ) & 0 \\ \sin(45^\circ) & \cos(45^\circ) & 0 \\ 0 & 0 & 1 \\ \end{pmatrix} $$

And last i translate the cube:

$$ \begin{pmatrix} 1 & 0 & 10 \\ 0 & 1 & 7 \\ 0 & 0 & 1 \\ \end{pmatrix} $$

When i combine this matrices i get my transformation matrix:

$$ \begin{pmatrix} 4\cos(45^\circ) & -4\sin(45^\circ) & 40\cos(45^\circ) - 28\sin(45^\circ) \\ 4\sin(45^\circ) & 4\cos(45^\circ) & 40\cos(45^\circ) + 28\sin(45^\circ) \\ 0 & 0 & 1 \\ \end{pmatrix} $$

But then i tried to apply this matrix to the point $(0,1,1)$ and i got an wrong result:

$$(5.6, 50.9116 ,1)$$

As you can see it should be around:

$$(7.1, 9.9, 1)$$

What did I wrong? Thanks!

1

There are 1 best solutions below

2
On BEST ANSWER

There is a mistake in your multiplication.

$$ T_{total}=\begin{pmatrix} 4\cos(45^\circ) & -4\sin(45^\circ) & 40\cos(45^\circ) - 28\sin(45^\circ) \\ 4\sin(45^\circ) & 4\cos(45^\circ) & \color{red}{28\cos(45^\circ) + 40\sin(45^\circ)} \\ 0 & 0 & 1 \\ \end{pmatrix} $$

But, since $sin (45^\circ)$ and $cos (45^\circ)$ have the same value, the problem is not from this point.

The problem is related to the order of the Transforms. In matrix multiplication, you should care about matrix order.

$T1$ is scale transform

$T2$ is rotation transform

$T3$ is translation transform

you computed:

$$X_{new}=(T1 \times T2 \times T3) \times X_{old}$$

while, you need to scale first then rotation then translation:

$$X_{new}=(T3 \times T2 \times T1) \times X_{old}$$

$$T3 \times T2 \times T1=\begin{pmatrix} 4\cos(45^\circ) & -4\sin(45^\circ) & 10 \\ 4\sin(45^\circ) & 4\cos(45^\circ) & 7 \\ 0 & 0 & 1 \\ \end{pmatrix}$$

$$T1\times T2 \times T3 \times \begin{pmatrix} 0 \\ 1 \\ 1 \\ \end{pmatrix}=\begin{pmatrix} 5.66 \\ 50.91 \\ 1 \\ \end{pmatrix}$$

While

$$T3\times T2 \times T1 \times \begin{pmatrix} 0 \\ 1 \\ 1 \\ \end{pmatrix}=\begin{pmatrix} 7.17 \\ 9.83 \\ 1 \\ \end{pmatrix}$$