Rotation Derivation Trick

A point P with coordinates (p_x, p_y) can be viewed as a linear combination of two unit vectors x_hat and y_hat:

To rotate the point about the origin through angle theta, we rotate the whole coodinate system. The new point P' also has coordinates (p_x, p_y) in the new system:

We want to find new coordinates (p_x', p_y') that represent P' in the old system:

Since all the hatted items are unit vectors, we can easily determine the new vectors x'_hat and y'_hat in terms of x_hat and y_hat:

These equations, in matrix form, can be substituted into the left side of equation (*):

Now the two matrices on the right can be composed to give the final coordinates: