Sharpwell Tutorials: Prof Manish Nadkarni 9820993770
Two-Dimensional Transformation
Computer graphics often requires geometric operations like:
An image is a set of points. Any geometric transformation requires a modification in the points as
per certain standard patterns. This can be done using a “Transformation Matrix” as described in the
examples below. In all the examples below, the 2nd matrix in each matrix equation is the
“Transformation Matrix”.
Scaling (in 2 dimensions):
Scaling in x-direction
𝑠 0
[𝑥 𝑦][ 𝑥 ] = [ 𝑠𝑥 𝑥 𝑦 ]
0 1
Here we observe that the x-coordinate of the point increases by a factor of sx. The y-coordinate
remains the same.
Scaling in y-direction
1 0
[𝑥 𝑦][ [ 𝑥 𝑠𝑦 𝑦 ]
0 𝑠𝑦 ] =
Here we observe that the y-coordinate of the point increases by a factor of sy. The x-coordinate
remains the same.
Scaling in both x and y-direction
𝑠 0
[𝑥 𝑦][ 𝑥 [ 𝑠𝑥 𝑥 𝑠𝑦 𝑦 ]
0 𝑠𝑦 ] =
Here we observe that both the x and y-coordinates of the point increase by factor sx and sy
respectively.
1|Page
Sharpwell Tutorials: Prof Manish Nadkarni 9820993770
Reflection:
Reflection about y-axis
[ 𝑥 𝑦 ] [−1 0 ] = [ −𝑥 𝑦 ]
0 1
Reflection about x-axis
[𝑥 𝑦][ 1 0 ] = [𝑥 −𝑦 ]
0 −1
Reflection about origin
[ 𝑥 𝑦 ] [ −1 0 ] = [−𝑥 − 𝑦 ]
0 −1
Shearing:
Shearing along positive direction of y axis (if b is negative, it is along negative direction of y axis)
[ 𝑥 𝑦 ] [ 1 𝑏 ] = [ 𝑥 𝑥𝑏 + 𝑦 ]
0 1
Shearing along positive direction of x axis (if c is negative, it is along negative direction of x axis)
[ 𝑥 𝑦 ] [ 1 0 ] = [ 𝑥 + 𝑦𝑐 𝑦 ]
𝑐 1
2D Rotation about origin
Rotation by angle Ɵ in anticlockwise direction
[ 𝑥 𝑦 ] [ 𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃 ] = [ 𝑥𝑐𝑜𝑠𝜃 − 𝑦𝑠𝑖𝑛𝜃 𝑥𝑠𝑖𝑛𝜃 + 𝑦𝑐𝑜𝑠𝜃]
−𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃
Rotation by angle Ɵ in clockwise direction
[ 𝑥 𝑦 ] [ 𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 ] = [ 𝑥𝑐𝑜𝑠𝜃 + 𝑦𝑠𝑖𝑛𝜃 − 𝑥𝑠𝑖𝑛𝜃 + 𝑦𝑐𝑜𝑠𝜃]
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃
2D Translation
To move point P in x and y direction by a distance t1 and t2 respectively.
[ 𝑥 𝑦 ] + [ 𝑡1 𝑡2 ] = [ 𝑥 + 𝑡1 𝑦 + 𝑡2 ]
Rotation about an arbitrary point
This can be achieved in 3 steps.
Step 1: Translation of the object such that the arbitrary point is brought to origin.
Step 2: Rotate the image
Step 3: Translation of the object such that the arbitrary point is restored to its original position.
In the method described above, scaling, rotation and shearing are all done by multiplying by
Transformation matrix. But translation is done by adding another matrix.
2|Page
Sharpwell Tutorials: Prof Manish Nadkarni 9820993770
Homogeneous coordinates
The point [ x y ] is represented by [ x y 1 ]
In homogeneous coordinates, all operation can be performed by multiplying by Transformation
matrix. Hence, a series of transformation to be performed sequentially can be easily done by
multiplying the transformation matrices in correct order.
Translation in homogeneous coordinates
1 0 0
[ x y 1] [ 0 1 0 ] = [ 𝑥 + 𝑡1 𝑦 + 𝑡2 1]
𝑡𝑥 𝑡𝑦 1
Rotation in homogeneous coordinates
𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃 0
[ x y 1 ] [ −𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0 ] = [ 𝑥 𝑐𝑜𝑠𝜃 − 𝑦 𝑠𝑖𝑛𝜃 𝑥 𝑠𝑖𝑛𝜃 − 𝑦 𝑐𝑜𝑠𝜃 1]
0 0 1
Take angle Ɵ positive for anticlockwise rotation and negative for clockwise rotation
Scaling in homogeneous coordinates
𝑠𝑥 0 0
[ x y 1] [ 0 𝑠𝑦 0 ] = [ 𝑥 𝑠𝑥 𝑦 𝑠𝑦 1]
0 0 1
Reflection in homogeneous coordinates
Transformation matrices for various kinds of reflection are as below:
1 0 0 −1 0 0 −1 0 0
[ 0 −1 0 ] [ 0 1 0] [ 0 −1 0 ]
0 0 1 0 0 1 0 0 1
Reflection about x-axis Reflection about y-axis Reflection about origin
Shearing in homogeneous coordinates
Transformation matrices for various kinds of shearing are as below:
1 0 0 1 𝑆ℎ𝑦 0
[ 𝑆ℎ𝑥 1 0] [0 1 0]
0 0 1 0 0 1
x shear y shear
3|Page
Sharpwell Tutorials: Prof Manish Nadkarni 9820993770
Combined Transformation
If transformations are to be done in sequence, we must multiply the transformation matrices in
correct order and get the new transformation matrix.
e.g. Consider a sequential transformation of 3 steps:
Scaling to double scale ; rotation anticlockwise by 90° ; translation (3 units in x and 5 units in y)
Scaling rotation translation
𝑠𝑥 0 0 𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃 0 1 0 0
[0 𝑠𝑦 0 ] [ −𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0] [ 0 1 0]
0 0 1 0 0 1 𝑡𝑥 𝑡𝑦 1
2 0 0 0 1 0 1 0 0
= [0 2 0 ] [ −1 0 0 ] [ 0 1 0]
0 0 1 0 0 1 3 5 1
0 2 0
= [ −2 0 0 ]
3 6 1
This is the new transformation matrix. In one step, it would perform all the three transformations
sequentially.
Three Dimensional Transformations
Homogeneous coordinates
𝑠𝑥 0 0 0
𝑠𝑥 0 0 0 𝑠𝑦 0 0
Scaling [0 𝑠𝑦 0] 0 0 𝑠𝑧 0
0 0 𝑠𝑧 0 0 0 1
[ ]
1 0 0 0
0 1 0 0
Translation 0 0 1 0
𝑇𝑥 𝑇𝑦 𝑇𝑧 1
[ ]
1 0 0 0
1 0 0 0 cosƟ sinƟ 0
Rotation about x axis [0 𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃 ] 0 -sinƟ cosƟ 0
0 − 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0 0 0 1
cosƟ 0 -sinƟ 0
𝑐𝑜𝑠𝜃 0 −𝑠𝑖𝑛𝜃 0 1 0 0
Rotation about y axis [ 0 1 0 ] sinƟ 0 cosƟ 0
𝑠𝑖𝑛𝜃 0 𝑐𝑜𝑠𝜃 0 0 0 1
cosƟ sinƟ 0 0
𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃 0 -sinƟ cosƟ 0 0
Rotation about z axis [ − 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0] 0 0 1 0
0 0 1 0 0 0 1
4|Page
Sharpwell Tutorials: Prof Manish Nadkarni 9820993770
Questions:
1. Consider a line AB such that A (1, 1) and B (2, 2). Obtain a matrix of transformation for scaling
the line AB in x-direction by factor 2. Plot both the lines. [ A’ (2, 1) B’ (4, 2)]
2. Consider a line AB such that A (1, 2) and B (3, 3). Perform reflection through y-axis and draw the
same. [ A’ (-1, 2) B’ (-3, 3)]
3. Consider a line AB such that A (1, 3) and B (4, 2). Perform reflection through x-axis and draw the
same. [ A’ (1, -3) B’ (4, -2)]
4. Consider a point A (2, -3). Perform reflection about the origin. [ A’ (-2, 3)]
5. A square ABCD has coordinates A (0, 0), B (3, 0), C (3, 3), D (0, 3). Rotate the square about point
A by 90° in anticlockwise direction.
6. Using homogeneous coordinates, apply the following sequence of transformations to a line AB,
where A (0, 0) and B (3, 2)
a. Anticlockwise rotation by 45°
b. Translation by factor (2, 1)
7. Using homogeneous coordinates, rotate the line AB about point A by 30°, where A (2, 2) and
B (4, 2)
8. Consider a square ABCD with A (1, 1), B (3, 1), C (3, 3) and D (1, 3). Rotate this square by 90°
clockwise about point A.
9. Write a transformation matrix with scaling factors 3, 4 and 2 in x, y and z directions respectively.
Use homogeneous coordinates.
10. Develop a single transformation matrix in 3 dimensions which does the following:
a. Reduces the size to 50% of original size
b. Rotates about the x-axis by 30°
c. Translates 2 units in x-direction
11. Using homogeneous coordinates, apply the following sequence of transformations to a point A,
where A (2, -1, 3).
a. Translation by -2 units in y-direction
b. Rotates about z-axis by 90°
5|Page