Lecture 4
Transformations
Associate Professor
Dr. Ashraf Abdelaziz Taha
Course Title: Computer Graphics
Semester: 1 2024 / 2025
Duration: 12 weeks
Geometric Transformation Functions
• Translations
• Scaling
• Rotation
-2-
Why Transformation
• Transformations are used to build or change a scene or to give the
description of a complex object that is composed of several parts
• Geometric transformations can be used to describe how objects move
around in a scene during an animation sequence or simply to view them
from another angle.
• We represent transformation as matrices (Why?)
• Easy to analyze mathematically.
• Matrices have a lot of libraries in software.
-3-
Translations
• Moving the original point position along a straight-line path to its
new location.
• Describing objects in relation to their own coordinate system
• Assume the object consists of a set of points (x, y).
• T = (tx , ty) is the translation vector
• We add translation distances tx and ty to the original coordinates
(x, y) to obtain the new coordinate position (x’, y’).
T = (tx , ty)
x’ = x + tx y’ = y + ty
-4-
Translating a point from position P to
position P’ using a translation vector T.
Two-dimensional translation equations in the matrix form P’ = P + T (3)
-5-
Moving a polygon from position (a)
to position (b) with the
translation vector (−5.50, 3.75).
-6-
Scaling
• Multiplying object positions (x, y) by scaling factors sx and sy to produce the
transformed coordinates (x’, y’):
x’ = sx . x y’ = sy . y
Scaling operation:
-7-
Uniform scaling:
Means the scalar is the same for all components
-8-
Non-uniform scaling: different scalars per component
-9-
Rotation
• A rotation R() repositions all points of an object by moving them
along a circular arc centered at the rotation point (xr , yr) by a given
rotation angle ()
Rotation of an object through angle θ around the axis point (xr , yr ) -10-
Rotation around the origin
Rotation of a point from position (x, y) to
position (x’, y’) through an angle () relative
to the coordinate origin.
The original angular displacement of the
point from the x axis is φ.
The original coordinates of the point in
polar coordinates are:
x = r cos φ, y = r sin φ
To calculate (x’ , y’):
y’ = r cos(φ + ) = r cos φ cos − r sin φ sin = x cos - y sin
y’ = r sin(φ + θ) = r cos φ sin + r sin φ cos = x sin + y cos
-11-
To calculate (x’ , y’):
y’ = x cos - y sin
y’ = x sin + y cos
P’ = R · P
-12-
Rotation is counterclockwise
-13-
Sequence of transformations for rotating an object around x axis -14-
Rotation around arbitrary point
• How to rotate around any point (xr , yr) ?
• Idea
• Translate the object by the vector (-xr , -yr)
• Rotate around the origin
• Translate the rotated object back by the vector (xr , yr)
-15-
Rotation around an arbitrary point
-16-
Scaling around an arbitrary point
-17-
Two-Dimensional Translation Matrix
• we can represent the equations for a two-dimensional translation of a
coordinate position using the following matrix multiplication:
P’ = T(tx, ty) · P
-18-
Two-Dimensional Rotation Matrix
Two-dimensional rotation transformation equations about the coordinate
origin can be expressed in the matrix form
P’ = R(θ) · P
-19-
Translation
Translation of a point
-20-
Scaling
Uniform Scaling
-21-
Pipeline operations
• Scaling with a selected fixed position
-22-
Rotation
-23-