If $x \cos\theta+y\sin\theta=a$ and $x\sin\theta-y\cos\theta=b$, then $\tan\theta=\frac{bx+ay}{ax-by}$. (Math Olympiad) I tried to solve it but I can’t get the answer. Please help me in proving this trig identity: 

If 
  $$x \cos\theta+y\sin\theta=a$$
  $$x\sin\theta-y\cos\theta=b$$ 
  then $$\tan\theta=\frac{bx+ay}{ax-by}$$

I've spent many hours trying.
Thanks in advance.

We may write the given equations as:
$$\begin{pmatrix}\cos \theta & - \sin \theta \\ \sin \theta & \cos \theta \end{pmatrix}   \begin{pmatrix}x \\ - y  \end{pmatrix}  = \begin{pmatrix}a \\ b  \end{pmatrix}  $$
and recognise that the first matrix represents a counterclockwise rotation by $\theta$ about the origin.
We can then use the formula for the tangent of the difference of two angles to see that
$$\tan \theta = \frac{\frac{b}{a}- \frac{-y}{x}}{1+\frac{b}{a} \frac{-y}{x}}=\frac{bx+ay}{ax-by}$$
