09-08-2022, 02:30 PM
(09-08-2022, 01:40 PM)luke Wrote: 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).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:
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).Code: (Select All)x = px(v) * COSr + SINr * py(v) ' ******* GALLEON
y = py(v) * COSr - px(v) * SINr ' ******* GALLEON
It's a matrix then. Thank you for pointing that out. I just read the Wikipedia page on the 2D rotation matrix and now it makes a bit more sense. Yes, you're right about rotation direction. Use a positive angle for counter-clockwise rotation and a negative angle (as Galleon did) for clockwise rotation according to the Wikipedia article.
So it would appear I need to read up on matrix math now and play around with this matrix to get a better understanding.
Thanks for the explanation Luke.