The real benefit comes from the combinability of the transformation matrices. The star in figure 1 is centered on the origin; this isn't particularly useful in a computer graphics scenario, since the origin is the upper-left corner of the screen.
To display this star, you want to translate it to screen coordinates. But once you do, it's no longer stretchable; simple scaling operations multiplying the x and y coordinates by the scaling factors occur relative to the origin. So, if the star was in the upper right as in figure Figure 3: Five-pointed star, centered at 50, Still; that's a lot of mathematical operations. This is where the matrix format earns its keep.
If you represent the translation and scale operations as matrices, you can "pre-multiply" them into a single uber matrix that can be applied as one to each point in the polygon. So working right-to-left :. Where c x ,c y is the centroid of the figure and s x and s y are the scale factors to apply. Of course, you don't need to work out the algebra like I did here; your GPU does all of that for you. You just plug in the three matrices and apply them.
So, given the polygon in figure 3 with centroid 50, 50 , to double it, you'd multiply the matrix:. Figure 5: Scaling done correctly. So this is 1 out here, e1 will look like that. Let me do it in a more vibrant color. Now let me write what e2 looks like. This is 1 in our x2 direction. Now if I rotate e1 by an angle theta, what will it look like?
So if I rotate e1 in angle theta -- I'll do it in this color right here-- it will still have a length of 1, but it'll be rotated like that and that angle right there is theta.
So this right here is the rotation of e1 by theta. These are all vectors, of course. That's what that is. Now what are the coordinates for this? Or how do we specify this new vector?
Well we can break out a little bit of our trigonometry. Its new x1 coordinate-- we could call it-- or its x1 entry is going to be this length right here.
So if we draw a right triangle, it is the side that is adjacent to theta. This side is a hypotenuse which is length 1. So how do we figure out this side? If we call this side the adjacent side.
The adjacent side over the hypotenuse. Adjacent-- let me write it over here. Adjacent over the hypotenuse which is just 1, is equal to the cosine of theta. Cosine is adjacent over hypoteneuse, and the adjacent side is going to be our new x1 coordinate, right? Well, we can obviously ignore that 1, a divided by 1 is equal to cosine theta, which means that a is equal to cosine theta, which means that this length of our rotated vector is equal to cosine theta.
Its horizontal component, or its horizontal coordinate is equal to cosine of theta. Now, what's its vertical component going to be? Its vertical component is going to be this height right here, which is the same thing as that height right there.
Or we could say sine of theta-- and call this the opposite-- sine of theta is equal to the opposite over 1. So this is going to be equal to sine of theta, right? So this vertical component is equal to sine of theta.
So the new rotated basis vector could be written as cosine of theta for its x component, or for its horizontal component. And sine of theta for its vertical component. This is the new rotated basis vector.
Now what about e2? We could do something very similar there. It's going to look like that. That angle right there is theta. We can create a little right triangle right there. And so if we want to know its x coordinate-- so now we're concerned with the rotation through an angle of theta of e2, which is that right there, of e2.
This is e2 right there. This is going to be equal to what? Its new x coordinate or its first entry in this vector if we wanted to draw it in standard position. Or the point that it is specifying is going to be equal to this distance, which is equal to this distance on this triangle.
But the coordinate is going to be the negative of this, right? If this is a distance of 2, this coordinate is going to be minus 2. So what's this? We have an angle. It's a right triangle. This is opposite to the angle. Opposite over 1, opposite over hypotenuse is equal to cosine of theta. So this opposite side is equal to the cosine of theta. So the x-coordinate right here. Oh sorry, my trigonometry is messing up.
Sine is equal to opposite-- let me write it-- sine of theta is equal to opposite over hypotenuse. So the sine of theta-- the sine of this angle is equal to the opposite over the hypotenuse. The hypotenuse is 1, has length 1 because these are the standard basis vectors.
So this is equal to the sine of theta. Now, this distance is equal to the sine of theta that's going in the negative direction, so it's going to be equal to the minus sine of theta. And then what it's new y component going to be of this rotated version of e2? Well, we just look right here. We have our angle. This is adjacent to the angle. This adjacent side over the hypotenuse-- adjacent over which is just this is adjacent right here is just going to be equal to cosine of theta.
So its new y-coordinate going to be cosine of theta. So when we apply the transformation to each of our basis vectors, we get A is equal to the transformation applied to e1 which is cosine of theta and sine of theta. And the transformation applied to e2, which is minus sine of theta times the cosine of theta. So now this is a big result. We've now been able to mathematically specify our rotation transformation using a matrix. So we can now say that the rotation transformation-- and it's a transformation from R2 to R it's a function.
We can say that the rotation through an angle of theta of any vector x in our domain is equal to the matrix cosine of theta, sine of theta, minus sine of theta, cosine of theta, times your vector in your domain, times x1 and x2. And you might be saying, oh Sal, we did all this work and that's kind of neat, but how do I apply this?
I still have all these cosines of thetas and sines of thetas there-- how I do it? Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. How do rotational matrices work? Asked 7 years, 8 months ago.
Active 7 years, 8 months ago. Viewed 3k times. Add a comment.
0コメント