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 ?  



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.
