In rotation, we rotate the object at particular angle θ (theta) from its origin. From the following figure, we can see that the point P(X, Y) is located at angle φ from the horizontal X coordinate with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you will get a new point P’ (X’, Y’).
Using standard trigonometric the original coordinate of point P(X, Y) can be represented as −
$X= r\ cos\phi$ ....(1)
$Y= r\ sin\phi$ ........(2)
Same way we can represent the point P’ (X’, Y’) as −
$X'=r\cos(\theta +\phi )=rcos\phi\ cos\theta\ -rsin\phi\ sin\theta$ ..........(3)
$Y'=r\sin(\theta +\phi )=rcos\phi\ sin\theta\ +rsin\phi\ cos\theta$ ............(4)
Substituting equation (1) & (2) in (3) & (4) respectively, we will get
$X'=Xcos\theta\ -Ysin\theta$
$Y'=Xsin\theta\ +Ycos\theta$
Representing the above equation in matrix form,
$\left [ X'Y' \right ]= \left [ XY \right ]\begin{bmatrix} cos\theta & sin\theta\\ -sin\theta& cos\theta \end{bmatrix}$
$P'= P . R$
Where R is the rotation matrix
$R=\begin{bmatrix} cos\theta &sin\theta \\ -sin\theta & cos\theta \end{bmatrix}$
The rotation angle can be positive and negative.
For positive rotation angle, we can use the above rotation matrix. However, for negative angle rotation, the matrix will change as shown below −
$R=\begin{bmatrix} cos(-\theta) &sin(-\theta) \\ -sin(-\theta) & cos(-\theta) \end{bmatrix}$
$R=\begin{bmatrix} cos\theta &-sin\theta \\ sin\theta& cos\theta \end{bmatrix}$