Get rotation angle between two plane coordinate systems 
This question is easy for sure - but I get confused with the sign of red rotation angle (when using atan), which I want to be negative for clockwise rotation and positive for CCW.  
The problem is illustrated below - I have given all blue Points (P1-P5), both in red and blue coordinates, and therefore also the blue angle. What is the easiest and fastest way to calculate the rotating angle with the right sign ?  


 A: You have a blue coordinate system and a red coordinate system such that the red system has been translated to pt5, and rotated by some angle.
You have many points in the red system, but know four points' coordinates in both systems. With this information, you would like to convert all your red coordinates into blue coordinates.
Perhaps the most illustrative way to solve this problem is to solve for the (homogeneous) transformation matrix from red to blue. It will have the following form:
$$T = \begin{vmatrix} \cos \theta & -\sin \theta & x_t \\ \sin \theta & \cos \theta & y_t \\ 0 & 0 & 1 \end{vmatrix} $$
In this matrix, $\theta$ is the (counterclockwise) angle you are looking for, and $x_t, y_t$ are the translation. Once these parameters have been solved for, you can multiple the matrix by any red coordinate, and the results will be a blue coordinate.
Now if $\vec{a_r}$ is a coordinate in the red system and $\vec{a_b}$ is its corresponding coordinate in the blue system, you have a set of equations $T\vec{a_r} = \vec{a_b}$. (Note that the coordinates should be represented as homogenized column vectors, so they should actually have three values: an $x$ a $y$, and the last value should always be 1.) Perform the multiplication to get a system of equations. If you do this with enough points (hopefully your four are sufficient), you should be able to get a unique solution.
A: Given that the red system is merely a translation and rotation of the blue system,
the "blue" coordinates $(x',y')$ of a point are
$$ \begin{pmatrix} x' \\ y' \end{pmatrix}
=  \begin{pmatrix} x'_5 \\ y'_5 \end{pmatrix}
  + \begin{pmatrix} c & -s \\ s & c \end{pmatrix}
    \begin{pmatrix} x \\ y \end{pmatrix}$$
where $(x,y)$ are the "red" coordinates of the same point and
$(x'_5, y'_5)$ are the "blue" coordinates of $P_5$.
This gives the equations
$$xc - ys = x' - x'_5,$$
$$xs + yc = y' - y'_5.$$
Knowing the coordinates $(x,y)$ and $(x',y')$ of just one point in both systems,
and knowing $(x'_5,y'_5)$, you now have two equations in two unknowns.
(Actually three equations, because you also have $c^2 + s^2 = 1$.)
The other three points are redundant, or perhaps better still you can use them
to check the calculations that used the first point. If you really want to get
fancy you can try to minimize the root mean squared error of all four sets of
blue coordinates after the transformation from red coordinates.
That's a little more complicated than a simple linear system, of course.
I chose $c$ and $s$ as variables because I wanted names that would remind one of
$\cos\theta$ and $\sin\theta$ without dragging in all the trigonometric baggage
that actually writing $\cos\theta$ and $\sin\theta$ might entail.
If the purpose is to convert the red coordinates of all points to blue
coordinates, you don't ever actually need to know $\theta$.
By the way, a translation plus rotation is a rotation, so the red coordinates are
the blue coordinates rotated about some point other than the origin of either system,
but I don't think you need to use that fact for what you want to do.
