2

Suppose, I have a 2D rectangle ABCD like the following:

$A(0,0)$, $B(140,0)$, $C(140,100)$, $D(0,100)$.

I want to rotate the whole rectangle by $\theta = 50°$.

enter image description here

I want to rotate it around the Z-axis by an arbitrary angle using a rotation transformation matrix.

How to do that?

I know that, $$ A = \begin{bmatrix} \ 0 & 0 & 1 \\ \end{bmatrix}; B = \begin{bmatrix} \ 140 & 0 & 1 \\ \end{bmatrix}; C = \begin{bmatrix} \ 140 & 100 & 1 \\ \end{bmatrix}; D = \begin{bmatrix} \ 0 & 100 & 1 \\ \end{bmatrix}. $$

And, I know that the rotation matrix is, $$R = \begin{bmatrix} \ cos \theta & -sin \theta & 0 \\ sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}$$

Now, what is the calculation?

I have tried the following ways,

$$Rotation = \begin{bmatrix} \ 0 & 0 & 1 \\ 140 & 0 & 1 \\ 140 & 100 & 1 \\ 0 & 100 & 1 \\ \end{bmatrix}.\begin{bmatrix} \ cos \theta & -sin \theta & 0 \\ sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}$$

And, $$ A' = \begin{bmatrix} \ 0 & 0 & 1 \\ \end{bmatrix} . \begin{bmatrix} \ cos \theta & -sin \theta & 0 \\ sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}\\ B' = \begin{bmatrix} \ 140 & 0 & 1 \\ \end{bmatrix} . \begin{bmatrix} \ cos \theta & -sin \theta & 0 \\ sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}\\ C' = \begin{bmatrix} \ 140 & 100 & 1 \\ \end{bmatrix} . \begin{bmatrix} \ cos \theta & -sin \theta & 0 \\ sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}\\ D' = \begin{bmatrix} \ 0 & 100 & 1 \\ \end{bmatrix} . \begin{bmatrix} \ cos \theta & -sin \theta & 0 \\ sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} $$

For example,

$$B' = \begin{bmatrix} \ 140 & 0 & 1 \\ \end{bmatrix} . \begin{bmatrix} \ cos 50^\circ & -sin 50^\circ & 0 \\ sin 50^\circ & cos 50^\circ & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} = \begin{bmatrix} \ 89.99 & -107.24 & 1 \\ \end{bmatrix}\\ C' = \begin{bmatrix} \ 140 & 100 & 1 \\ \end{bmatrix} . \begin{bmatrix} \ cos 50^\circ & -sin 50^\circ & 0 \\ sin 50^\circ & cos 50^\circ & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} = \begin{bmatrix} \ 166.59 & -42.96 & 1 \\ \end{bmatrix}$$ What is the right way to work with?

  • The rotated rectangle is completely determines by the left and bottom vectors. Use this matrix $$\begin{pmatrix} \cos \theta & -\sin \theta \ \sin \theta & \cos \theta \end{pmatrix}$$ – Mr.Fry Jul 27 '15 at 01:27
  • What is the scale of the picture? The grid doesn't correspond to the points you listed. It's also odd that the origin didn't get preserved by your transformation; what do you get when you calculate $A', B', C', D'$? If the origin is at the intersection of the two blue lines, then even your original rectangle isn't getting accurately represented ... – Théophile Jul 27 '15 at 01:40
  • 1
    Those are the correct matrices, at least up to the direction of rotation. (The ones you show are meant to be used by putting them on the left side of a column vector and multiplying, not by putting them on the right side of a row vector as you showed; but at worst that would just rotate the rectangle in the wrong direction, not turn it into a non-rectangular parallelogram as shown.) So I suspect the problem is in the details of exactly how you used the software, which you have not shown. This may even be a StackOverflow question rather than MSE. – David K Jul 27 '15 at 02:17
  • Whether you're writing the vector to the right or left of the matrix determines whether you want the minus with the upper or lower $\sin \theta$. But even if you use "the wrong one", it should only change whether the angle is $50^\circ$ or $-50^\circ$. The fact that angles aren't preserved is alarming though. Can you list the actual matrix you're using? – pjs36 Jul 27 '15 at 02:17

2 Answers2

0

When you show $B'$ as $(5,7)$ it is rotated by about 54.5^\circ and the length of the side is now $\sqrt{74} \approx 8.6$, not $7$ This is a problem with your expectation, not the code. You also have the sign of the sine backwards if you are using row vectors-rotate $(1,0,1)$ by $45^\circ$ and it should be $(\frac 12\sqrt 2, \frac 12\sqrt 2,1)$ but you put a minus sign on the second coordinate. A proper rotation of $B$ by $50^\circ$ is $(7 \cos 50^\circ, 7 \sin 50^\circ)\approx (4.5,5.36)$. $C'=(7 \cos 50^\circ-5 \sin 50^\circ, 7 \sin 50^\circ + 5 \cos 50^\circ)\approx(0.6693,8.576)$

Ross Millikan
  • 374,822
  • I have given you some test points. The difference between $7$ as the length of a side and $8.6$ as the new length seemed large to me. If your code does not return these values, you have a bug. – Ross Millikan Jul 27 '15 at 02:48
  • You still have the wrong rotation sign. – Ross Millikan Jul 27 '15 at 02:55
  • Yes. Your question had a disconnect between the rotation matrix and the use of row vectors. One way to solve that is to reverse the sign of the $\sin$ term. Another is to reverse the sign of $\theta$. They have the same effect. That won't fix taking a rectangle to a parallelogram, so I suspect you are not rotating the points correctly. – Ross Millikan Jul 27 '15 at 03:01
0

I have solved my problem.

$$Rotation = \begin{bmatrix} \ 0 & 0 & 0 \\ 140 & 0 & 0 \\ 140 & 100 & 0 \\ 0 & 100 & 0 \\ \end{bmatrix}.\begin{bmatrix} \ cos \theta & -sin \theta & 0 \\ sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}$$

Alternatively,

$$ A' = \begin{bmatrix} \ 0 & 0 & 0 \\ \end{bmatrix} . \begin{bmatrix} \ cos \theta & sin \theta & 0 \\ -sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} = \begin{bmatrix}0 & 0 & 0\end{bmatrix}\\ B' = \begin{bmatrix} \ 140 & 0 & 0 \\ \end{bmatrix} . \begin{bmatrix} \ cos \theta & sin \theta & 0 \\ -sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} = \begin{bmatrix}98.9949 & 98.9949 & 0\end{bmatrix}\\ C' = \begin{bmatrix} \ 140 & 100 & 0 \\ \end{bmatrix} . \begin{bmatrix} \ cos \theta & sin \theta & 0 \\ -sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} = \begin{bmatrix}28.2843 & 169.706 & 0\end{bmatrix}\\ D' = \begin{bmatrix} \ 0 & 100 & 0 \\ \end{bmatrix} . \begin{bmatrix} \ cos \theta & sin \theta & 0 \\ -sin \theta & cos \theta & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} = \begin{bmatrix}-70.7107 & 70.7107 & 0\end{bmatrix}\\ $$