Unit Iii
Unit Iii
Facilitator: Frank
Course code: CS 8205
Email: [email protected]
Tel:+255757050205
Introduction
Transformation means changing some graphics into
something else by applying rules.
We can have various types of transformations such
as translation, scaling up or down, rotation,
shearing, etc.
When a transformation takes place on a 2D plane,
it is called 2D transformation.
Transformations play an important role in
computer graphics to reposition the graphics on the
screen and change their size or orientation.
Homogenous Coordinates
To perform a sequence of transformation such
as translation followed by rotation and scaling,
we need to follow a sequential process
Translate the coordinates
Rotate the translated coordinates, and then
Scale the rotated coordinates to complete the
composite transformation.
To shorten this process, we have to use 3×3
transformation matrix instead of 2×2
transformation matrix.
To convert a 2×2 matrix to 3×3 matrix, we have
to add an extra dummy coordinate W.
In this way, we can represent the point by 3
numbers instead of 2 numbers, which is called
Homogenous Coordinate system.
In this system, we can represent all the
transformation equations in matrix multiplication.
A point (x, y) can be re-written in homogeneous
coordinates as (xw, yw, w)
The homogeneous parameter w is a non- zero value
such that x and y coordinates can easily be
recovered by dividing the first and second numbers
by the third.
Translation
A translation moves an object to a different
position on the screen.
We translate a point by adding to the x and y
coordinates, respectively.
We translate an object by translating each vertex
in the object.
You can translate a point in 2D by adding
translation coordinate to the original
coordinate X, Y to get the new coordinate X ′, Y
′.
The new point: (x’, y’)
Or p p T where
x x tx
P p T
y y ty
In matrix
x x t x
t
y y y
Examples 01
Given a circle C with radius 10 and center
coordinates (1, 4). Apply the translation with
distance 5 towards X axis and 1 towards Y axis.
Obtain the new coordinates of C without changing
its radius.
How to translate an object with multiple
vertices?
2D Rotation
Is the process of rotating an object with respect to
an angle in xy plane.
Default rotation center: Origin (0,0)
Positive values for the rotation angle define
counterclockwise rotations about the pivot point,
and negative values rotate objects in the clockwise
direction.
x’ = r cos (φ + θ)
= r cos(φ) cos(θ) – r sin(φ) sin(θ)
= x cos(θ) – y sin(θ)
y’ = r sin (φ + θ)
= r sin(φ) cos(θ) + r cos(φ)sin(θ)
= y cos(θ) + x sin(θ)
x’ = x cos(θ) – y sin(θ)
y’ = y cos(θ) + x sin(θ)
Matrix form
x cos( ) sin( ) x
y sin( ) cos( ) y
Or p p.R
Example:
Given a line segment with starting point as (0, 0)
and ending point as (4, 4). Apply 30 degree
rotation anticlockwise direction on the line
segment and find out the new coordinates of the
line.
Scaling
Scaling is a process of modifying or altering the
size of objects.
Scaling may be used to increase or reduce the
size of object.
Scaling can be achieved by multiplying the
original coordinates of the object with the
scaling factor to get the desired result.
If scaling factor > 1, then the object size is
increased.
If scaling factor < 1, then the object size is
reduced.
Let us assume that the original coordinates are
x, y, the scaling factors are sx , s y and the
produced coordinates are x′, y′.
This can be mathematically represented as
shown below
x x.sx y y.s y
The transformation equations can also be
written in the matrix form:
x sx 0 x
0 s
y y y
Or P’ = P . S
THREE DIMENSIONAL TRANSFORMATION
When the transformation takes place on a 3D
plane, it is called 3D transformation
The translation, scaling and rotation
transformations used for 2D can be extended to
three dimensions.
In 3D, each transformation is represented by a
4x4 matrix.
Using homogeneous coordinates it is possible to
represent each type of transformation in a
matrix form and integrate transformations into
one matrix
To apply transformations, simply multiply
matrices, also easier in hardware and software
implementation
Homogeneous coordinates: 4 components
Transformation matrices: 4×4 elements
P’= T . P where
Very similar to 2D transformation
Translation
x’ = x + y’ = y + z’ = z +
Example
Given a 3D object with coordinate points A(0,
3, 1), B(3, 3, 2), C(3, 0, 0), D(0, 0, 0). Apply
the translation with the distance 1 towards X
axis, 1 towards Y axis and 2 towards Z axis and
obtain the new coordinates of the object.
3D Rotation
Rotation needs an angle and an axis.
In 3D, rotation is about a vector, which can be
done through rotations about x, y or z axes.
Positive rotations are anti-clockwise, negative
rotations are clockwise, when looking down a
positive axis towards the origin.
In 3 dimensions, there are 3 possible types of
rotation-
X-axis Rotation
Y-axis Rotation
Z-axis Rotation
For X-Axis Rotation-
For Y-Axis Rotation
For Z-Axis Rotation
Example
Given a homogeneous point (1, 2, 3). Apply
rotation 90 degree towards X, Y and Z axis and
find out the new coordinate points
3D Scaling
You can change the size of an object using
scaling transformation .
In the scaling process , you either expand or
compress the dimensions of the object .
Scaling can be achieved by multiplying the
original coordinates of the object with scaling
factor to get the desired result
The general transformation matrix for scaling is
Example
Given a 3D object with coordinate points A(0, 3,
3), B(3, 3, 6), C(3, 0, 1), D(0, 0, 0). Apply the
scaling
parameter 2 towards X axis, 3 towards Y axis and
3 towards Z axis and obtain the new coordinates of
the object.
Homework
A unit square is transformed by 2 x 2
transformation matrix. The resulting position
vector are :-
0286,
0341
what is the transformation matrix?
A unit square is transformed by 2 x 2
transformation matrix. The resulting position
vector are :-
0286,
0341
what is the transformation matrix?
GOODBYE
frank