You are on page 1of 27

Lecture 4: 2D Transformations

Dr. Mazen Nabil Elagamy


Dr. Noha Ghatwary
 Basic idea: f transforms x to f (x)
Matrix multiplication is linear combination of columns

Row * Col
 The geometric-transformation functions, which are available in all
graphics packages are those for translation, rotation, and scaling.
 Other useful transformation routines, which are sometimes included in a
package are reflection and shearing operations
 2D Translation is a process of moving an object from one position to another in a two
dimensional plane.
 To translate a two-dimensional position, we add translation distances (tx) and (ty) to the
original coordinates (xold, yold) to obtain the new coordinate position (xnew, ynew).
 The translation distance pair (tx, ty) is called a translation vector or shift vector.
 We can express Equations (1) as a single matrix equation by using the following
column vectors to represent coordinate positions and the translation vector:
xnew = xold + tx ynew = yold + ty
 Translation is a rigid-body transformation, which moves objects without deformation.
 That is, every point on the object is translated by the same amount.
 A straight-line segment is translated by applying the equation to each of the two line
endpoints and redrawing the line between the new endpoint positions.
 Similarly, to translate a polygon we add a translation vector to the coordinate position of
each vertex and then regenerate the polygon using the new set of vertex coordinates.
 Moving a polygon from position (a) to position (b) with the translation vector (−5.50, 3.75).
 Moving a circle from position (a) to position (b) with the translation vector (5, 1).

 Old center coordinates of C = (Xold, Yold) = (1, 4)

 Translation vector = (Tx, Ty) = (5, 1)

 Let the new center coordinates of C = (Xnew, Ynew).

 Applying the translation equations, we have-

 Xnew = Xold + Tx = 1 + 5 = 6

 Ynew = Yold + Ty = 4 + 1 = 5

 Thus, New center coordinates of C = (6, 5).


 We generate a rotation transformation of an object by specifying a rotation axis and a
rotation angle.
 Initial coordinates of the object O = (Xold, Yold)
 Initial angle of the object O with respect to origin = Φ
 Rotation angle = θ
 New coordinates of the object O after rotation = (Xnew, Ynew)
 This rotation is achieved by using the following rotation equations-
Xnew = Xold * cosθ – Yold * sinθ
Ynew = Xold * sinθ + Yold * cosθ
 Given a triangle with corner coordinates A(0, 0), B(1, 0) and C(1, 1). Rotate the triangle by 90
degree anticlockwise direction and find out the new coordinates.

 For Coordinates A(0, 0)  For Coordinates B(1, 0)  For Coordinates C(1, 1)

 Let the new coordinates of corner A  Let the new coordinates of corner B  Let the new coordinates of corner C
after rotation = (Xnew, Ynew). after rotation = (Xnew, Ynew). after rotation = (Xnew, Ynew).

 Xnew= Xold * cosθ – Yold * sinθ=  Xnew= Xold * cosθ – Yold * sinθ= 1 x  Xnew= Xold x cosθ – Yold * sinθ= 1 *
0 * cos90º – 0 x sin90º= 0 cos90º – 0 * sin90º= 0 cos90º – 1 * sin90º= 0 – 1= -1

 Ynew= Xold x sinθ + Yold x cosθ= 0 *  Ynew= Xold *sinθ + Yold * cosθ= 1*sin90º  Ynew= Xold * sinθ + Yold * cosθ= 1 *
sin90º + 0 * cos90º= 0 + 0 * cos90º= 1 + 0= 1 sin90º + 1 * cos90º= 1 + 0= 1

 Thus, New coordinates of corner A  Thus, New coordinates of corner B  Thus, New coordinates of corner C
after rotation = (0, 0). after rotation = (0, 1). after rotation = (-1, 1).
 Thus, New coordinates of the triangle after rotation = A (0, 0), B(0, 1), C(-1, 1).
 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 subjects the coordinate points of the original object to change.
Scaling factor determines whether the object size is to be increased or reduced.
If scaling factor > 1, then the object size is increased.
If scaling factor < 1, then the object size is reduced.
 Initial coordinates of the object O = (Xold, Yold)
 Scaling factor for X-axis = Sx
 Scaling factor for Y-axis = Sy
 New coordinates of the object O after scaling = (Xnew, Ynew)
 This scaling is achieved by using the following scaling equations-
Xnew = Xold * Sx
Ynew = Yold * Sy
 Given a square object with coordinate 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 coordinates of the object.
 Given: Scaling factor along X axis = 2, Scaling factor along Y axis = 3
 For Coordinates A(0, 3)  For Coordinates B(3, 3)

 Xnew = Xold * Sx = 0 x 2 = 0  Xnew = Xold * Sx = 3 x 2 = 6

 Ynew = Yold * Sy = 3 x 3 = 9  Ynew = Yold * Sy = 3 x 3 = 9

 Thus, New coordinates of corner  Thus, New coordinates of corner


A after scaling = (0, 9). B after scaling = (6, 9).

 For Coordinates C(3, 0)  For Coordinates D(0, 0)

 Xnew = Xold * Sx = 3 x 2 = 6  Xnew = Xold * Sx = 0 x 2 = 0

 Ynew = Yold * Sy = 0 x 3 = 0  Ynew = Yold * Sy = 0 x 3 = 0

 Thus, New coordinates of corner  Thus, New coordinates of corner


C after scaling = (6, 0). D after scaling = (0, 0).
 Reflection is a kind of rotation where the angle of rotation is 180 degree.
 The reflected object is always formed on the other side of mirror.
 The size of reflected object is same as the size of original object.
 Assume:
- Initial coordinates of the object O = (Xold, Yold)
- New coordinates of the reflected object O after reflection = (Xnew, Ynew)

 This reflection is achieved by using the following reflection equations-


Xnew = Xold
Ynew = -Yold
 Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection on the
X axis and obtain the new coordinates of the object.
For Coordinates A(3, 4) For Coordinates B(6, 4)
 Xnew = Xold = 3  Xnew = Xold = 6
 Ynew = -Yold = -4  Ynew = -Yold = -4
 Thus, New coordinates of corner A  Thus, New coordinates of corner B
after reflection = (3, -4). after reflection = (6, -4).

 For Coordinates C(5, 6)

 Xnew = Xold = 5 New coordinates of the triangle after


reflection = A (3, -4), B(6, -4), C(5, -6).
 Ynew = -Yold = -6
 Thus, New coordinates of corner
C after reflection = (5, -6).
 2D Shearing is an ideal technique to change the shape of an existing object in a two
dimensional plane.
 In a two dimensional plane, the object size can be changed along X direction as well as Y
direction. So, there are two versions of shearing:
 Shearing in X direction
 Shearing in Y direction

Shearing in X direction Shearing in Y direction


 Initial coordinates of the object O = (Xold, Yold)
 Shearing parameter towards X direction = Shx
 Shearing parameter towards Y direction = Shy
 New coordinates of the object O after shearing = (Xnew, Ynew)

Shearing in X Axis- Shearing in Y Axis-


 Shearing in X axis is achieved by using the  Shearing in Y axis is achieved by using the
following shearing equations- following shearing equations-
 Xnew = Xold + Shx * Yold  Xnew = Xold
 Ynew = Yold  Ynew = Yold + Shy * Xold
 Given a triangle with points A (1, 1), B(0, 0) and C(1, 0). Apply shear parameter
2 on X axis and 2 on Y axis and find out the new coordinates of the object.

 For Coordinates A(1, 1)  For Coordinates B(0, 0)  For Coordinates C(1, 0)

 Xnew = Xold + Shx * Yold = 1 + (2 * 1)  Xnew = Xold + Shx * Yold = 0 + (2 *  Xnew = Xold + Shx * Yold = 1 + 2 * 0 = 1
=3 0) = 0
 Ynew = Yold = 0
 Ynew = Yold = 1  Ynew = Yold = 0
 Thus, New coordinates of corner C
 Thus, New coordinates of corner  Thus, New coordinates of corner B
A after shearing = (3, 1). after shearing = (0, 0). after shearing = (1, 0).

Thus, New coordinates of


the triangle after shearing
in X axis = A (3, 1), B(0, 0),
C(1, 0)
 Given a triangle with points A (1, 1), B(0, 0) and C(1, 0). Apply shear parameter
2 on X axis and find out the new coordinates of the object.

 For Coordinates A(1, 1)  For Coordinates B(0, 0)  For Coordinates C(1, 0)

 Xnew = Xold = 1  Xnew = Xold = 0  Xnew = Xold = 1

 Ynew = Yold + Shy * Xold = 1 + 2 *  Ynew = Yold + Shy * Xold = 0 + 2 *  Ynew = Yold + Shy * Xold = 0 + 2* 1
1=3 0=0 =2
 Thus, New coordinates of  Thus, New coordinates of  Thus, New coordinates of corner
corner A after shearing = (1, 3). corner B after shearing = (0, 0) C after shearing = (1, 2).

Thus, New coordinates of


the triangle after shearing
in Y axis = A (1, 3), B(0, 0),
C(1, 2).
 Transformations can be interpreted as operations that
move points in space
- e.g., for modeling, animation
 Change of coordinate system - e.g., screen and view
transforms
 Construct complex transformations as compositions of
basic transforms

You might also like