How to rotate a whole rectangle by an arbitrary angle around the origin using a transformation matrix? 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°$.

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?
 A: 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)$
A: 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}\\
$$
