Function to map points inside a rotated rectangle. The problem we are trying to solve is one from an app but this is not really a programming problem which is why I'm asking here.
We are mapping user locations inside a football field on a map. The football field will be a real world football field and could be rotated at any angle.
So the corners A, B, C, D could be at...
A = (0, 0) 
B = (8, 8) 
C = (12, 5) 
D = (4, -3)

(These are not an exact rectangle but they act as an illustration, the actual rectangle would be an exact rectangle).
We would then like to display the tracked locations inside a football field shown the right way up in the phone.
With the points...
A' = (0, 0)
B' = (0, 11.3)
C' = (5, 11.3)
D' = (5, 0)

What we are looking for is a function to map any point p at position (x, y) inside the original football field to a point p' at position (x', y')
Please let me know if I need to provide more information but I think I've covered everything.
 A: I've answered assuming $A$ is always $(0,0)$. The algorithm is only slightly more complex if this is not the case. For notation, I'm using $A_x$ to be the $x$-coordinate of $A$ and so on.
Consider your points as vectors, so that $P = \begin{bmatrix}P_x \\ P_y\end{bmatrix}$. Then to find $P'$, you just want to multiply $P$ by the appropriate rotation matrix, $$P' = \begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta)\end{bmatrix} P = \begin{bmatrix} \cos(\theta) \cdot P_x -\sin(\theta) \cdot P_y \\ \sin(\theta) \cdot P_x + \cos(\theta) \cdot P_y \end{bmatrix}. $$
Finding the angle of rotation is especially easy if one of the sides of your rectangle (in this case, $A'D'$) lies along the $x$ axis and $A$ stays fixed at the origin: you need only to find the angle of $D = \begin{bmatrix} D_x \\ D_y \end{bmatrix}$ as a vector (negated, since you're rotating from $R$ to $R'$ rather than from $R'$ to $R$). Since $A$ is at the origin, this is $$\theta = -\tan (D_y / D_x)$$
