I don't like the use of trigonometry here.  There are only four possible cases for rotateAngle, and I think a switch statement enumerating the cases would be much easier to understand and maintain.  And also faster.