Page 57 - Computer Graphics
P. 57
56
The light gray "F" in this picture shows what would be drawn without the
translation; the dark red "F" shows the same "F" drawn after applying a translation
by (4,2). The top arrow shows that the upper left corner of the "F" has been moved
over 4 units and up 2 units. Every point in the "F" is subjected to the same
displacement. Note that in my examples, I am assuming that the y-coordinate
increases from bottom to top. That is, the y-axis points up.
Remember that when you give the command translate(e,f), the translation
applies to all the drawing that you do after that, not just to the next shape that you
draw. If you apply another transformation after the translation, the second
transform will not replace the translation. It will be combined with the translation,
so that subsequent drawing will be affected by the combined transformation. For
example, if you combine translate (4,2) with translate (-1,5), the result is the same
as a single translation, translate (3,7). This is an important point, and there will
be a lot more to say about it later.
Also remember that you don't compute coordinate transformations
yourself. You just specify the original coordinates for the object (that is, the object
coordinates), and you specify the transform or transforms that are to be applied.
The computer takes care of applying the transformation to the coordinates. You
don't even need to know the equations that are used for the transformation; you
just need to understand what it does geometrically.
Rotation
A rotation transforms, for our purposes here, rotates each point about the origin,
(0,0). Every point is rotated through the same angle, called the angle of rotation.
For this purpose, angles can be measured either in degrees or in radians. (The 2D
graphics APIs that we will look at later in this chapter use radians, but OpenGL
uses degrees.) A rotation with a positive angle rotates objects in the direction from
the positive x-axis towards the positive y-axis. This is counter clockwise in a
coordinate system where the y-axis points up, as it does in my examples here, but
it is clockwise in the usual pixel coordinates, where the y-axis points down rather
than up. Although it is not obvious, when rotation through an angle of r radians
about the origin is applied to the point (x,y), then the resulting point (x1,y1) is
given by
x1 = cos(r) * x - sin(r) * y
y1 = sin(r) * x + cos(r) * y