I'll expand on MarkT's post above, starting from the very basics, so that everyone can follow. (Also, MarkT, your rotation matrix is transposed wrt. standard right-handed coordinate system and column vectors: it's usually the upper right sine that is negated, not the lower left one. It only affects the rotation direction, the same way as negating the angle in radians or degrees.)

Code:

```
c = cos(radians) = cos(degrees · π / 180)
s = sin(radians) = sin(degrees · π / 180)
atan2(s, c) = atan2(R·s, R·c) = radians, radians · 180 / π = degrees
where R is any nonzero real number (can be even negative).
⎡ x ⎤ ⎡ x'⎤ ⎡ c -s ⎤
v = ⎢ ⎥, v' = ⎢ ⎥, R = ⎢ ⎥
⎣ y ⎦ ⎣ y'⎦ ⎣ s c ⎦
⎡ x'⎤ ⎡ c -s ⎤ ⎡ x ⎤
v' = R v ⇔ ⎢ ⎥ = ⎢ ⎥ ⎢ ⎥
⎣ y'⎦ ⎣ s c ⎦ ⎣ y ⎦
⎧ x' = c x - s y
⇔ ⎨
⎩ y' = s x + c y
```

The prime

`'`

is just one way to differentiate variables. It just means that

`x`

and

`x'`

are separate variables, as are

`y`

and

`y'`

. We could just as well call these

`oldx`

,

`newx`

,

`oldy`

, and

`newy`

, but the prime notation is more common and therefore useful to know, making these formulae easier to read.

Zero angle is towards positive x axis, 90° = π/2 is towards positive y axis, ±180° = ±π is towards negative x axis, and -90° = +270° = 3π/2 = -π/2 is towards negative y axis. Thus, positive angles rotate from positive x axis to positive y axis.

No rotation is trivial:

`c`

=1 and

`s`

=0, which leads to

`x'=x`

and

`y'=y`

, no change.

Rotation by multiples of 90° are trivial, because one of

`c`

and

`s`

is zero and the other is +1 or -1.

Rotation by 45° has

`c`

=

`s`

=√½≃0.7071067812. Additional multiples of 90° (the other diagonal directions) only change the signs.

To add scaling, you can multiply both

`c`

and

`s`

by the same positive real number. If it is less than 1, it will shorten the result compared to the original; if it is greater than 1, it will lengthen the result compared to original.