Lesson6
Lesson6
OF
AGRICULTURE & TECHNOLOGY
JKUAT SODeL
Nairobi, Kenya
E-mail: [email protected]
Back Close 0
ICS 2311 Computer Graphics
LESSON 6
Transformations
6.1. introduction
JKUAT SODeL
Back Close 1
ICS 2311 Computer Graphics
There are several kinds of transformations in computer graph-
ics:
• projection transformations,
• viewing transformations, and
JKUAT SODeL
• modeling transformations.
Your graphics API should support all of these, because all will
be needed to create your images. Projection transformations are
©2014
Back Close 2
ICS 2311 Computer Graphics
and relationships of those items.
Together these make up the graphics pipeline that we dis-
cussed in the first chapter of these notes. Among the modeling
transformations, there are three fundamental kinds: rotations,
JKUAT SODeL
general models than you can create with only simple modeling
techniques. Later in this chapter we will describe the relation-
ship between objects in a scene and how you can build and
maintain these relationships in your programs.The real power
of modeling transformation, though, does not come from us-
JJ II ing these simple transformations on their own. It comes from
J I combining them to achieve complete control over your modeled
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 3
ICS 2311 Computer Graphics
objects.
The individual simple transformations are combined into a
composite modeling transformation that is applied to your ge-
ometry at any point where the geometry is specified.
JKUAT SODeL
Back Close 4
ICS 2311 Computer Graphics
6.1.1. Definitions
In this section we outline the concept of a geometric transfor-
mation and describe the fundamental transformations used in
computer graphics, and describe how these can be used to build
JKUAT SODeL
• Transformations
©2014
Back Close 5
ICS 2311 Computer Graphics
the objects we apply them to, so the basic transformations we
work with are those that maintain geometry, which are the three
we mentioned earlier: rotations, translations, and scaling.
Below we look at each of these transformations individually
JKUAT SODeL
Back Close 6
ICS 2311 Computer Graphics
the ball, then discuss rotation and show how the ball can be ro-
tated around one of its short axes, then discuss translations and
show how the ball can be moved to any location we wish, and
finally will show how the transformations can work together to
JKUAT SODeL
create a rotating, moving ball like we might see if the ball were
kicked. The ball is shown with some simple lighting and shading
as described in the chapters below on these topics.
©2014
• Scaling
Scaling changes the entire coordinate system in space by mul-
tiplying each of the coordinates of each point by a fixed value.
Each time it is applied, this changes each dimension of every-
thing in the space. A scaling transformation requires three val-
JJ II
ues, each of which controls the amount by which one of the three
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 7
ICS 2311 Computer Graphics
coordinates is changed, and a graphics
API function to apply a scaling transformation will take
three real values as its parameters.
Thus if we have a point (x, y, z) and specify the three scaling
JKUAT SODeL
values as Sx, Sy, and Sz, then the point is changed to (x*Sx,
y*Sy, z*Sz) when the scaling transformation is applied.
If we take a simple sphere that is centered at the origin and
©2014
Back Close 8
ICS 2311 Computer Graphics
possibly distorting its shape. This shows that it is most useful
to apply scaling to an object defined at the origin so only the
dimensions of the object will be changed.
• Rotation
JKUAT SODeL
is defined.
The rotation will always leave a line through the origin in
the space fixed, that is, will not change the coordinates of any
point on that line. To define a rotation transformation, you need
to specify the amount of the rotation (in degrees or radians, as
needed) and the line about which the rotation is done.
JJ II
A graphics API function to apply a rotation transformation,
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 9
ICS 2311 Computer Graphics
JKUAT SODeL
©2014
JJ II
J I
J DocDoc I Figure 6.1: a sphere a scaled by 2.0 in the y-direction to make
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close a rugby ball (left) and the same sphere is shown unscaled (right) 10
ICS 2311 Computer Graphics
then, will take the angle and the line as its parameters; remem-
ber that a line through the origin can be specified by three real
numbers that are the coordinates of the direction vector for that
line.
JKUAT SODeL
• Translation
Translation takes everything in your space and changes each
point’s coordinates by adding a fixed value to each coordinate.
The effect is to move everything that is defined in the space
by the same amount.
JJ II
To define a translation transformation, you need to specify
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 11
ICS 2311 Computer Graphics
the three values that are to be added to the three coordinates
of each point.
A graphics API function to apply a translation, then, will
take these three values as its parameters. A translation shows a
JKUAT SODeL
Back Close 12
ICS 2311 Computer Graphics
JKUAT SODeL
©2014
Back Close 13
ICS 2311 Computer Graphics
appropriately, creating a composite transformation as discussed
in the next section. Then rotation and translation values were
computed for several times in the flight of the ball, allowing us
to rotate the ball by slowly-increasing amounts and placing it as
JKUAT SODeL
Back Close 14
ICS 2311 Computer Graphics
drawSphere()
Notice that the ball rotates in a slow counterclockwise direc-
tion as it travel from left to right, while the position of the ball
describes a parabola as it moves, modeling the effect of gravity
JKUAT SODeL
Back Close 15
ICS 2311 Computer Graphics
a rectangular box with height A, width B, and depth C, with
center at (C1,C2,C3), and oriented at an angle A relative to
the Z-axis, you could start with a cube one unit on a side and
with center at the origin, and get the box you want by applying
JKUAT SODeL
and third, translate the cube to the position C1, C2, C3.
This sequence is critical because of the way transformations
work in the whole space. For example, if we rotated first and
then scaled with different scale factors in each dimension, we
would introduce distortions in the box. If we translated first
JJ II and then rotated, the rotation would move the box to an entirely
J I different place. Because the order is very important, we find that
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 16
ICS 2311 Computer Graphics
there are certain sequences of operations that give predictable,
workable results, and the order above is the one that works best:
apply scaling first, apply rotation second, and apply translation
last.
JKUAT SODeL
erations, operations for which f*g ¹ g*f (that is, f(g(x)) ¹ g(f(x))
). Most students have little experience with noncommutative
operations until you get to a linear algebra course, so this may
be a new idea.
But let’s look at the operations we described above: if we
JJ II take the point (1, 1, 0) and apply a rotation by 90° around the
J I Z-axis, we get the point (-1, 1, 0). If we then apply a translation
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 17
ICS 2311 Computer Graphics
by (2, 0, 0) we get the point (1, 1, 0) again.
However, if we start with (1, 1, 0) and first apply the trans-
lation, we get (3, 1, 0) and if then apply the rotation, we get
the point (-1, 3, 0) which is certainly not the same as (1, 1, 0).
JKUAT SODeL
Back Close 18
ICS 2311 Computer Graphics
(sequence here) and the same rotations in a different sequence
(different sequence here) then the results are quite different, as
is shown
JKUAT SODeL
©2014
JJ II
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 19
ICS 2311 Computer Graphics
Revision Questions
Solution:
©2014
Back Close 20
ICS 2311 Computer Graphics
are necessary.
• Perspective Projections: In perspective projection, all the
rays pass through one point in space, the centre of projection.
The projection of a 3D point onto the z=f plane is calculated
JKUAT SODeL
Back Close 21
ICS 2311 Computer Graphics
in 2D and 3D graphic design?
JKUAT SODeL
©2014
JJ II
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 22
ICS 2311 Computer Graphics
Solutions to Exercises
Exercise 1.
Back Close 23