You are on page 1of 35

COMPUTER GRAPHICS AND

ANIMATION
09 Transformations

Transformations
Some basic transformations:
Scaling
Rotation
Translation

Essential to many graphics applications.


Example: city-planning application
Translation for placing symbols (of trees, buildings,
etc) at appropriate positions
Scaling for sizing the symbols
Rotation for orienting the symbols.

Transformations
Matrices can be used as operators to
perform transformations.
Basically:
P = P . T
P = original point
T = transformation matrix
P = result point

Scaling
Scaling based on
(0,0)
P is scaled by sx
along the x axis and
by sy along the y
axis.
Thus:
x = sx . X
y = sy . y

Scaling
In matrix form:
x = sx . x + 0 . y
y = 0 . x + sy . y
Thus:

Rotation
Center of rotation at
(0,0).
P is rotated
degrees counterclockwise.

Rotation
In matrix form:
x = x cos y sin
y = x sin + y cos
Thus:

Shearing
Im lost at words, so
describe this yourself.
dx = dy / m
=y/m

Shearing
In matrix form:
x = x + y/m
y=y
Thus:

where a = 1/m
What about shearing along the y axis?

Translation
Move P dx units
parallel to the x
axis and dy untis
parallel to the y
axis

Translation
We get:
x = x + dx
y = y + dy
P = P + T
How would the transformation matrix be?
P = P . T
T = ???

Transformation
We want to capture all the tranformations
in the form of a matrix.
Make it so that P = P . T can be applied
for all kinds of transformations, including
translation.
Is it possible to have a transformation
matrix incorporating translation?

Homogeneus Coordinates
Scale, rotate, shear : P = P . T
Translation : P = P + T
Transform P(x,y) into a homogeneous
coordinate Ph(x,y,w)
This coordinate system has multiple
values for same points
E.g.: (2,3,6) and (4,6,12) are the same point.

Homogeneous Coordinates
At P2, w = 1
P2(x/w, y/w, 1)
P1 and P2
represent the same
point.

Homogeneous Coordinates
Let P(x,y,1) and P(x, y, w)
x = ax + by + m
y = cy + dy + n
The transformation matrix changes from
2x2 to 3x3, thus:

P (x, y, 1)

Transformation Operators
Scaling Shearing

S(sx, sy)

Rotation

R()

Shy(a)

Translation

T(dx, dy)

Shx(b)

Transforming Lines
To transform a line, you only need to
transform the end points. The other points
will follow.

Composition of Transformations
The process of applying several
transformations in succession to form one
overall transformation
If we transform a point P with M1 (resulting
in P), and then transform the result using
M2 (resulting in P), we get:
P = P . M1
P = P . M2
Thus: P = P . M1 . M2

Composition of Transformations
If we perform n succesive transformations
on a point P, we get:
P = P . M1 . M2 . M3 . ... . Mn

Example
How do we rotate a shape degrees from
an arbitrary point P?
For each point in the shape P i, we perform
these 3 steps:
Translate such that P is the origin (M1)
Rotate (M2)
Translate back to original point (M3)

Example

Example
Let P(x,y)

Example
T = M1 . M2 . M3

Data Structure
Type TMatrix = array [0 .. 2, 0
.. 2] of real
Type TPoint
< x : real, y : real>
Type THC = array [0 .. 2] of
real {homogenous coordinate}
Type THC
< x : real, y : real, w : real>

Review Questions
Why do we use 3x3 matrices instead of 2x2
matrices for 2D transformations?
Derive the transformation matrix for scaling a point
from (0,0).
Derive the transformation matrix for rotating a
point from (0,0).
Derive the transformation matrix for shearing a
point on the x axis and y axis.
Derive the transformation matrix for translating a
point.
In general, how do we perform a scaling or rotation
operation from an arbitrary point?

Exercise
Find the transformation matrices for the
following operations:
Translate a point by (4, 2)
Scale the x-component of a point by 0.5 and the
y-component by 3 from (0,0).
Rotate a point 45 degrees clockwise from (0,0)
Shear a point on the line y = 2x along the x axis.

Perform the above transformations on the


point (3,4)

Exercise
Define the transformation matrix for the
following operations:
Vertical flip (reflect to x-axis)
Transpose point (P(y,x))
Reflection from an arbitrary point P.
An object is to be reflected twice as far from
the line x = 5. For example, if P is (0,0) and P'
is the result of the transformation, P' is (15,0).
Derive the transformation matrix.

Exercise
Prove that R(1) R(2) = R(1 + 2). What
does this mean?
Prove that T(x1, y1) . T(x2, y2) = T(x1+x2,
y1+y2). What does this mean?
Prove that S(x1, y1) . S(x2, y2) = S(x1x2,
y1y2)

Exercise
An orthogonal matrix is a matrix which,
when multiplied by its transpose, results in
the identity matrix. Hence, the inverse of an
orthogonal matrix is the transpose of the
matrix.
Prove that rotation matrices are orthogonal.
What does this mean?

Exercise
Find the transformation matrix for the
following operations:
Scaling an object from the origin point by 2
in x and y, followed by a translation by (1,1).
Translation of an object by (1,1) followed by
a scaling from the origin by 2 in x and y.
Why are the two resulting matrices
different?

Exercise
What 2D transformations are done to
transform the shape on the left to the
shape on the right? Explain. Derive the
transformation matrix.

Exercise
What 2D transformations are done to
transform the shape on the left to the
shape on the right? Explain. Derive the
transformation matrix.

Exercise
The following matrix M is a transformation matrix:

Let M1 and M2 be transformation matrices such that


M = M1 M2.
Define M1 and M2 if:
M1 is a translation operator and M2 is a scaling
operator.
M1 is a scaling operator and M2 is a transliation
operator.

Exercise
A point is to be transformed in such a way that
the distance from the point (3, 4) is halved. For
example, if P is (1, 2) (distance = 22 from (3,
4)) and P' is the result of the transformation, P' is
(2, 3) (distance = 2 from (3, 4)). Derive the
transformation matrix.

Exercise
Below is a rectangle specified by its four vertices A, B, C,
and D. Determine a set of individual 2D transformation
matrices that transform the rectangle ABCD into
rectangle ABCD as shown below. Note that the
transformations should, in the end, transform vertex A
into A, B into B, etc.

You might also like