CHAPTER 2: All That Math Jazz (^35)
Figure 2-2. Rotating around the common origin
Naturally things get more complicated while we have to dust off the high school trig. The
task at hand is to find out where the corners of the square would be after an arbitrary
rotation, a. Eyes are glazing over across the land.
Note By convention counterclockwise rotations are considered positive, while clockwise are
negative.
So, consider x and y as the coordinates of one of our square’s vertices, and the square
is normalized. Unrotated, any vertex would naturally map directly into our coordinate
system of x and y. Fair enough. Now we want to rotate the square by an angle a.
Although its corners are still at the ‘‘same’’ location in the square’s own local coordinate
system, they are different in ours, and if we’re wanting to actually draw the object, we
need to know the new coordinates of x’ and y’.
Now we can jump directly to the trusty rotation equations, because ultimately that’s
what the code will express:
x′=xcos(a)−ysin(a) y'=xsin(a)+ycos(a)
Doing a really quick sanity check, you can see that if a is 0 degrees (no rotation), x’ and
y’ reduce to the original x and y coordinates. If the rotation is 90 degrees, then sin(a)=1,
cos(a)=0, so x’=-y, and y'=x. It’s exactly as expected.
singke
(singke)
#1