1. How to derive coordinate translation and rotation
The rotation of 2D coordinates can be derived with trigonometric formulas.
In geometric transformations we often need to rotate all the points of a coordinate system; this operation is called a rigid-body rotation (all points rotate while their relative positions stay unchanged). The figure below shows a typical rigid-body rotation in a 2D coordinate system. We rotate the blue coordinate system by θ degrees, and the new coordinate system is the red one. Suppose we know the coordinates of a point relative to the red coordinate system ($x_{red}$, $x_{red}$ ) and the rotation angle θ, and we want to find the coordinates of that point relative to the blue coordinate system ($x_{blue}$,$y_{blue}$)

This is actually simple and can be solved easily with high-school trigonometry. From the figure, the invariant is the length of the black line segment, which we can compute from the coordinates of the black point in the red coordinate system ($x_{red}$, $x_{red}$ ). The length of the black segment is $r=\sqrt {x_{red}^2+y_{red}^2}$
Then, using the purple triangle, we can compute the coordinates of the black point relative to the blue coordinate system ($x_{blue},y_{blue}$)
From high-school trigonometry we know that:
$
x_{blue}=r*cos(\alpha+\theta) \tag{1}
$
$
y_{blue}=r*sin(\alpha+\theta) \tag{2}
$
$\alpha$ is unknown, but we can find a clue about it.
$$
x_{red}=r*cos(\alpha)\\
y_{red}=r*sin(\alpha)
$$
Expanding (1) and (2) gives:
$$
\begin{align}
x_{blue}&=r∗cos(α+θ)=r∗(cos(α)∗cos(θ)−sin(α)∗sin(θ))=x_{red}∗cos(θ)−y_{red}∗sin(θ)\\
y_{blue}&=r∗sin(α+θ)=r∗(sin(α)∗cos(θ)+cos(α)∗sin(θ))=y_{red}∗cos(θ)+x_{red}∗sin(θ)
\end{align}
$$
