TRANSFORMATIONS OF OBJECTS
1
Transformation
• Transformation is the application of some mathematical
rules to an object or a pixel to bring about some change
to it.
• This change can be a displacement of an object from
one point to another or a change in its size or shape.
• Two types of transformations are
Solid body transformations
Affine transformations
Solid body transformations
• In Solid body transformations shape of the object after the
transformation is applied to it is not distorted or changed.
• The shape remains intact after the object is transformed.
• In ‘solid body’ transformations the following properties of
the objects are preserved.
▪ The distances between the points of the object are
preserved.
▪ The ratios of the distance between the points of the
object are preserved.
▪ The angles after and before the transformations remain
the same.
▪ Parallel lines remain parallel after the transformation.
EXAMPLE OF
TRANSFORMATIONS
The house has been scaled, rotated and translated, in
both 2D and 3D.
5
USING TRANSFORMATIONS (2)
In 3D, many cubes make a city.
6
USING TRANSFORMATIONS (3)
• The snowflake exhibits symmetries.
• We design a single motif and draw the whole shape
using appropriate reflections, rotations, and
translations of the motif.
7
USING TRANSFORMATIONS (5)
• In a computer animation, objects move.
• We make them move by translating and rotating
their local coordinate systems as the animation
proceeds.
• A number of graphics platforms, including
OpenGL, provide a graphics pipeline: a sequence
of operations which are applied to all points that are
sent through it.
• A drawing is produced by processing each point.
8
THE OPENGL GRAPHICS PIPELINE
This version is simplified.
9
Affine transformations
• Affine transformations are the transformations that change the
shape of the object they are applied on but they do not distort the
object.
• Affine transformations have the following properties.
▪ The distances between the points are not preserved.
▪ The angles are not preserved.
▪ The ratios of the distances between the points are preserved.
▪ Parallel lines remain parallel after the transformations are
applied.
▪ Affine transformations include i) Scaling ii) Shear
AFFINE TRANSFORMATIONS
Matrix form of the affine transformation in 2D:
For a 2D affine transformation the third row of the matrix is always (0, 0,
1).
11
AFFINE TRANSFORMATIONS (5)
• Some people prefer to use row matrices to represent points and
vectors rather than column matrices: e.g., P = (Px, Py, 1)
• In this case, the P vector must pre-multiply the matrix, and the
transpose of the matrix must be used: Q = P M T.
12
AFFINE TRANSFORMATIONS
When vector V is transformed by the same affine transformation as point
P, the result is
Important: to transform a point P into a point Q, post-multiply M by P: Q = M P.
13
AFFINE TRANSFORMATIONS
• Example: find the image Q of point P = (1, 2, 1) using the
affine transformation
14
GEOMETRIC EFFECTS OF AFFINE
TRANSFORMATIONS
Combinations of four elementary transformations:
(a) a translation, (b) a scaling, (c) a rotation, and (d)
a shear (all shown below).
15
TRANSLATIONS
• The amount P is translated does not depend on P’s
position.
• It is meaningless to translate vectors.
• To translate a point P by a in the x direction and b
in the y direction use the matrix:
• Only using homogeneous coordinates allow us to
include translation as an affine transformation.
16
Translation of point:
• To translate a point from coordinate position (x, y) to
another (x, y), we add algebraically the translation
distances Tx & Ty to the original co-ordinates.
• Translation equation:
• x1 = x + Tx y1 = y + Ty (The translation pair (Tx, Ty)
is called as shift vector)
• Example:
• Given a square with coordinate points A (0, 3), B (3, 3), C
(3, 0), D (0, 0). Apply the translation with distance 1
towards X axis and 1 towards Y axis. We have to find the
new co-ordinates of the square.
• Solution: Given-
• Old co-ordinates of the square = A (0, 3), B (3, 3), C (3, 0),
D (0, 0)
• Translation vector = (Tx, Ty) = (1, 1)
• For Coordinates A (0, 3)
• Let the new coordinates of corner A = (Xnew, Ynew).
• Applying the translation equations, we have-
• Xnew= Xold + Tx = 0 + 1 = 1
• Ynew= Yold + Ty = 3 + 1 = 4
• Thus, New coordinates of corner A = (1, 4).
• For Coordinates B (3, 3)
• Let the new coordinates of corner B = (Xnew, Ynew).
• Applying the translation equations, we have-
• Xnew= Xold + Tx = 3 + 1 = 4
• Ynew= Yold + Ty = 3 + 1 = 4
• Thus, New coordinates of corner B = (4, 4).
• For Coordinates C (3, 0)
• Let the new coordinates of corner C = (Xnew, Ynew).
• Applying the translation equations, we have-
• Xnew= Xold + Tx = 3 + 1 = 4
• Ynew= Yold + Ty = 0 + 1 = 1
• Thus, New coordinates of corner C = (4, 1).
• For Coordinates D (0, 0)
• Let the new coordinates of corner D = (Xnew, Ynew).
• Applying the translation equations, we have-
• Xnew= Xold + Tx = 0 + 1 = 1
• Ynew= Yold + Ty = 0 + 1 = 1
• Thus, New coordinates of corner D = (1, 1).
SCALING
• Scaling is about the origin.
• If Sx = Sy the scaling is uniform; otherwise it distorts the
image.
• If Sx or Sy < 0, the image is reflected across the x or y axis.
• The matrix form is
20
EXAMPLE OF SCALING
• The scaling (Sx, Sy) = (-1, 2) is applied to a collection of points.
• Each point is both reflected about the y-axis and scaled by 2 in
the y-direction.
21
TYPES OF SCALING
• Pure reflections, for which each of the scale
factors is +1 or -1.
• A uniform scaling, or a magnification about
the origin: Sx = Sy, magnification |S|.
▪Reflection also occurs if Sx or Sy is negative.
▪If |S| < 1, the points will be moved closer to the
origin, producing a reduced image.
• If the scale factors are not the same, the
scaling is called a differential scaling.
22
Formula for the Scaling:
• Let us have object O on which we will perform
the scaling.
• initial coordinates of the object O = (x ,
y).
• scaling factor in x-direction = Sx
• scaling factor in y-direction = Sy
• new coordinates after scaling = (x1, y1)
• hence we have equations for scaling :
• x1 = Sx * x
• y1 = Sy * y
• matrix representation
• SCALE EXAMPLE:
• Problem Statement: Given a square object
with co-ordinate points A (0, 3), B (3, 3), C
(3, 0), D (0, 0). Apply the scaling parameter
2 towards X axis and 3 towards Y axis and
obtain the new co-ordinates of the object.
• Solution:
• Given,
• Old corner coordinates of the square = A (0,
3), B (3, 3), C (3, 0), D (0, 0)
• Scaling factor along X axis = 2
• Scaling factor along Y axis = 3
• For the Coordinate A (0, 3):
• Let the new coordinates of corner A after scaling =
(Xnew, Ynew).
• When we apply the scaling equation, we get,
• Xnew = Xold x Sx = 0 x 2 = 0
Ynew = Yold x Sy = 3 x 3 = 9
• Thus, the new coordinates of corner A after scaling =
(0, 9).
• For the Coordinate B (3, 3):
• Let the new coordinates of corner B after scaling =
(Xnew, Ynew).
• When we apply the scaling equation, we get-
• Xnew = Xold x Sx = 3 x 2 = 6
Ynew = Yold x Sy = 3 x 3 = 9
• Thus, the new coordinates of corner B after scaling =
• For the Coordinate C (3, 0):
• Let the new coordinates of corner C after scaling =
(Xnew, Ynew).
• When we apply the scaling equation, we get-
• Xnew = Xold x Sx = 3 x 2 = 6
Ynew = Yold x Sy = 0 x 3 = 0
• Thus, the new coordinates of corner C after scaling =
(6, 0).
• For the Coordinate D (0, 0):
• Let the new coordinates of corner D after scaling =
(Xnew, Ynew).
• When we apply the scaling equation, we get-
• Xnew = Xold x Sx = 0 x 2 = 0
Ynew = Yold x Sy = 0 x 3 = 0
• Thus, the new coordinates of corner D after scaling =
ROTATION
• Counterclockwise around origin by angle θ:
28
Example2: Rotate a line CD whose endpoints are (3, 4) and (12, 15)
about origin through a 45° anticlockwise direction.
Solution: The point C (3, 4)
• Example3: Rotate line AB whose endpoints are A (2, 5) and B (6, 12) about
origin through a 30° clockwise direction.
SHEAR
Shear H about origin: x
depends linearly on y in
the figure.
for example, italic
letters).
33
Shearing in X Axis-
• Shearing in X axis is achieved by using the following shearing equations-
• Xnew = Xold + Shx x Yold
• Ynew = Yold
Shearing in Y Axis-
• Shearing in Y axis is achieved by using the following shearing equations-
• Xnew = Xold
• Ynew = Yold + Shy x Xold
• In Matrix form, the above shearing equations may be represented as-
Problem-01:
• Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply
shear parameter 2 on X axis and 2 on Y axis and find out
the new coordinates of the object.
• Solution-
• Old corner coordinates of the triangle = A (1, 1), B(0, 0),
C(1, 0)
• Shearing parameter towards X direction (Shx) = 2
• Shearing parameter towards Y direction (Shy) = 2
• Shearing in X Axis-
• For Coordinates A(1, 1)
• Let the new coordinates of corner A after shearing = (Xnew,
Ynew).
• Applying the shearing equations, we have-
• Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
• Ynew = Yold = 1
• Thus, New coordinates of corner A after shearing = (3, 1).
• For Coordinates B(0, 0)
•
• Let the new coordinates of corner B after shearing = (Xnew, Ynew).
•
• Applying the shearing equations, we have-
• Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0
• Ynew = Yold = 0
•
• Thus, New coordinates of corner B after shearing = (0, 0).
•
• For Coordinates C(1, 0)
•
• Let the new coordinates of corner C after shearing = (Xnew, Ynew).
•
• Applying the shearing equations, we have-
• Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1
• Ynew = Yold = 0
•
• Shearing in Y Axis-
• For Coordinates A(1, 1)
• Let the new coordinates of corner A after shearing = (Xnew, Ynew).
• Applying the shearing equations, we have-
• Xnew = Xold = 1
• Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3
• Thus, New coordinates of corner A after shearing = (1, 3).
• For Coordinates B(0, 0)
• Let the new coordinates of corner B after shearing = (Xnew, Ynew).
• Xnew = Xold = 0
• Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0
• Thus, New coordinates of corner B after shearing = (0, 0).
• For Coordinates C(1, 0)
• Let the new coordinates of corner C after shearing = (Xnew, Ynew).
• Applying the shearing equations, we have-
• Xnew = Xold = 1
• Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2
• Thus, New coordinates of corner C after shearing = (1, 2).
INVERSE TRANSLATION AND SCALING
Inverse of translation T-1:
Inverse of scaling S-1:
44
INVERSE ROTATION AND
SHEAR
• Inverse of rotation R = R(-θ):
-1
• Inverse of shear H-1: generally h=0 or g=0.
45
COMPOSING AFFINE
TRANSFORMATIONS
• Usually, we want to apply several affine
transformations in a particular order to the
figures in a scene: for example,
▪translate by (3, - 4)
▪then rotate by 30o
▪then scale by (2, - 1) and so on.
• Applying successive affine transformations is
called composing affine transformations.
46