0% found this document useful (0 votes)
11 views

Lesson6

The document provides an overview of transformations in computer graphics, focusing on their importance in creating and manipulating images. It details three fundamental types of transformations: scaling, rotation, and translation, and emphasizes the need for composite transformations to achieve desired graphical effects. The document also discusses the significance of the order in which these transformations are applied to avoid distortions in the final output.

Uploaded by

kevinnjuguna811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lesson6

The document provides an overview of transformations in computer graphics, focusing on their importance in creating and manipulating images. It details three fundamental types of transformations: scaling, rotation, and translation, and emphasizes the need for composite transformations to achieve desired graphical effects. The document also discusses the significance of the order in which these transformations are applied to avoid distortions in the final output.

Uploaded by

kevinnjuguna811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

JOMO KENYATTA UNIVERSITY

OF
AGRICULTURE & TECHNOLOGY
JKUAT SODeL

SCHOOL OF OPEN, DISTANCE AND eLEARNING


P.O. Box 62000, 00200
©2014

Nairobi, Kenya
E-mail: [email protected]

ICS 2311 Computer Graphics

JJ II LAST REVISION ON October 16, 2014


J I
J DocDoc I
Back Close
ICS 2311 Computer Graphics
This presentation is intended to covered within one week.
The notes, examples and exercises should be supple-
mented with a good textbook. Most of the exercises have
solutions/answers appearing elsewhere and accessible by
JKUAT SODeL

clicking the green Exercise tag. To move back to the same


page click the same tag appearing at the end of the solu-
tion/answer.
©2014

Errors and omissions in these notes are entirely the re-


sponsibility of the author who should only be contacted
through the Department of Curricula & Delivery
(SODeL) and suggested corrections may be e-mailed to
[email protected].
JJ II
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

Back Close 0
ICS 2311 Computer Graphics
LESSON 6
Transformations

6.1. introduction
JKUAT SODeL

Transformations are probably the key point in creating signifi-


cant images in any graphics system. It is extremely difficult to
model everything in a scene in the place where it is to be placed,
©2014

and it is even worse if you want to move things around in real


time through animation and user control.
Transformations let you define each object in a scene in any
space that makes sense for that object, and then place it in the
world space of a scene as the scene is actually viewed. Transfor-
JJ II mations can also allow you to place your eyepoint and move it
J I around in the scene.
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

those that specify how your scene in 3-space is mapped to the


2D screen space, and are defined by the system when you choose
perspective or orthogonal projections; viewing transformations
are those that allow you to view your scene from any point in
space, and are set up when you define your view environment,
JJ II and modeling transformations are those you use to create the
J I items in your scene and are set up as you define the position
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

translations, and scaling.


These all maintain the basic geometry of any object to which
they may be applied, and are fundamental tools to build more
©2014

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

The modeling transformation can be saved at any state and


later restored to that state to allow you to build up transfor-
mations that locate groups of objects consistently. As we go
©2014

through the chapter we will see several examples of modeling


through composite transformations.
Finally, the use of simple modeling and transformations to-
gether allows you to generate more complex graphical objects,
but these objects can take significant time to display. You may
JJ II want to store these objects in pre-compiled display lists that can
J I execute much more quickly.
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

very general graphical object models for your scenes.

• Transformations
©2014

A transformation is a function that takes geometry and pro-


duces new geometry. The geometry can be anything a computer
graphics systems works with—a projection, a view, a light, a
direction, or an object to be displayed.
We have already talked about projections and views, so in
JJ II this section we will talk about projections as modeling tools. In
J I this case, the transformation needs to preserve the geometry of
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

and together to see how we can use transformations to create


the images we need.
Our vehicle for looking at transformations will be the cre-
©2014

ation and movement of a rugby ball. This ball is basically an


ellipsoid (an object that is formed by rotating an ellipse around
its major axis), so it is easy to create from a sphere using scaling.
Because the ellipsoid is different along one axis from its shape
on the other axes, it will also be easy to see its rotations, and
JJ II of course it will be easy to see it move around with translations.
J I So we will first discuss scaling and show how it is used to create
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

scale it by 2.0 in one direction (in our case, the y-coordinate or


vertical direction), we get the rugby ball that is shown in Figure
below next to the original sphere. It is important to note that
this scaling operates on everything in the space, so if we happen
to also have a unit sphere at position farther out along the axis,
JJ II scaling will move the sphere farther away from the origin and
J I will also multiply each of its coordinates by the scaling amount,
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

takes everything in your space and changes each coordinate by


rotating it around the origin of the geometry in which the object
©2014

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

It is most useful to apply rotations to objects centered at the


origin in order to change only the orientation with the transfor-
mation.
©2014

• 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

very consistent treatment of everything in the space, so a trans-


lation is usually applied after any scaling or rotation in order
to take an object with the right size and right orientation and
©2014

place it correctly in space.

• Finally, we put these three kinds of transformations to-


gether to create a sequence of images of the rugby ball as it
moves through space, rotating as it goes, shown in Figure 2.5.
JJ II This sequence was created by first defining the rugby ball with a
J I scaling transformation and a translation putting it on the ground
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

Back Close 12
ICS 2311 Computer Graphics
JKUAT SODeL
©2014

JJ II Figure 6.2: a sequence of images of the rugby ball as transfor-


J I mations move it through space
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

if it were in a standard gravity field.


Each separate image was created with a set of transforma-
tions that can be generically described by
©2014

translate( Tx, Ty, Tz )


rotate( angle, x-axis )
scale( 1., 2., 1. )
drawBall()
where the operation drawBall() was defined as
JJ II translate( Tx, Ty, Tz )
J I scale( 1., 2., 1. )
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

on the ball’s flight.


This kind of composite transformation constructions is de-
scribed in the next section, and as we point out there, the order
©2014

of these transformation calls is critical in order to achieve the


effect we need.

6.1.2. Composite transformations


In order to achieve the image you want, you may need to apply
JJ II more than one simple transformation to achieve what is called
J I a composite transformation. For example, if you want to create
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

the following sequence of operations: first, scale the cube to the


right size to create the rectangular box with dimensions A, B, C,
second, rotate the cube by the amount A to the right orientation,
©2014

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

The order of transformations is important in ways that go


well beyond the translation and rotation example above. In
general, transformations are an example of noncommutative op-
©2014

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

That is, using some pseudocode for rotations, translations, and


point setting, the two code sequences
rotate(90, 0, 0, 1) translate(2, 0, 0)
©2014

translate (2, 0, 0) rotate(90, 0, 0, 1)


setPoint(1, 1, 0) setPoint(1, 1, 0)
produce very different results; that is, the rotate and trans-
late operations are not commutative.
This behavior is not limited to different kinds of transfor-
JJ II mations. Different sequences of rotations can result in different
J I images as well. Again, if you consider the sequence of rotations
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

Example . Briefly describe the two common classes of pla-


nar geometric projections with an overview of their associated
parametric and Projection equations
JKUAT SODeL

Solution:
©2014

• Parallel Projections: If the direction of a projector is given


by vector d=[dx, dy, dz], and it passes through the vertex V=[Vx,
Vy, Vz] it may be expressed by the parametric line equation: P
= V + µd In orthographic projection the projectors are perpen-
dicular to the projection plane, such that Px = Vx and Py = Vy
Thus, the x and y co-ordinates of the projected vertex is equal to
JJ II
the x and y co-ordinates of the vertex itself and no calculations
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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

as follows.If the centre of projection is at the origin, and we are


projecting the point V then the projector has equation: P =
µV 
©2014

Example . What is texture mapping?


Solution:

• Method of improving surface appearance by adding details


on surface. Image is ‘pasted’ onto a polygon. 
JJ II
J I Exercise 1.  Why is Texture mapping an important stage
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

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.

• Texture mapping allows you to glue an image of a brick wall


JKUAT SODeL

(obtained, perhaps, by scanning in a photograph of a real wall)


to a polygon and to draw the entire wall as a single polygon.
• Texture mapping ensures that all the right things happen
©2014

as the polygon is transformed and rendered. For example, when


the wall is viewed in perspective, the bricks may appear smaller
as the wall gets farther from the viewpoint.
• Depicting vegetation on large polygons representing the
ground in flight simulation; wallpaper patterns; and textures
JJ II that make polygons look like natural substances such as marble,
J I wood, or cloth. Exercise 1
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation

Back Close 23

You might also like