The 57.3 division factor is 180 / pi, a change from degrees to radians.
Rob's code first defines four characteristic points, the corners. If we can work out how to transform them, we can just redraw the triangles that connect them and the whole image will be rotated.
Each of the four points is a 2D (x, y) vector. It is a well known result from linear algebra that a vector can be rotated through an angle a by multiplying it by the rotation matrix:
So we have x' = x cos(a) - y sin(a), y' = x sin(a) + y cos(a).
Rob's SINr and COSr are sin(a) and cos(a) respectively. These lines:
then apply the formulas above with the caveat that x & y are swapped. This is just a matter of convention, the original matrix could have been written differently (I think it's just a matter of which way your rotation is going).
Rob's code first defines four characteristic points, the corners. If we can work out how to transform them, we can just redraw the triangles that connect them and the whole image will be rotated.
Each of the four points is a 2D (x, y) vector. It is a well known result from linear algebra that a vector can be rotated through an angle a by multiplying it by the rotation matrix:
Code: (Select All)
.- - - - - -
| cos(a) -sin(a) | |x| = |x cos(a) - y sin(a) | = |x'|
| sin(a) cos(a) | |y| |x sin(a) + y cos(a) | |y'|
.- - - - - -
Rob's SINr and COSr are sin(a) and cos(a) respectively. These lines:
Code: (Select All)
x = px(v) * COSr + SINr * py(v) ' ******* GALLEON
y = py(v) * COSr - px(v) * SINr ' ******* GALLEON