Lecture 6
Lecture 6
Lecture 6
In computer graphics, 2D Translation is a process of moving an object from one position to another
in a two-dimensional plane.
Consider a point object O has to be moved from one position to another in a 2D plane.
Let-
Initial coordinates of the object O = (Xold, Yold)
New coordinates of the object O after translation = (X new, Ynew)
Translation vector or Shift vector = (Tx, Ty)
Given a Translation vector (Tx, Ty)-
Tx defines the distance the Xold coordinate has to be moved.
Ty defines the distance the Yold coordinate has to be moved.
This translation is achieved by adding the translation coordinates to the old coordinates of
the object as-
Xnew = Xold + Tx (This denotes translation towards X axis)
Ynew = Yold + Ty (This denotes translation towards Y axis)
1 0 3
0 1 7
0 0 1
13 23 23 18 18 28 28 20 13 13
17 17 32 32 17 17 37 57 37 17
1 1 1 1 1 1 1 1 1 1
60
50
40
30
20
10
0
-60 -50 -40 -30 -20 -10 0 10 20 30
Problem-02:
Given a circle C with radius 10 and center coordinates (1, 4). Apply the translation with a
distance of 5 towards the X-axis and 1 towards Y Y-axis. Obtain the new coordinates of C
without changing its radius.
Solution-
Given-
Old center coordinates of C = (Xold, Yold) = (1, 4)
Translation vector = (Tx, Ty) = (5, 1)
Alternatively,
In matrix form, the new center coordinates of C after translation may be obtained as-
Thus, New center coordinates of C = (6, 5).
Problem-01:
Given a line segment with starting point as (0, 0) and ending point as (4, 4). Apply a 30-
degree rotation anticlockwise direction on the line segment and find out the new coordinates
of the line.
Solution-
We rotate a straight line by its end points with the same angle. Then, we re-draw a line
between the new end points.
Given-
Old ending coordinates of the line = (Xold, Yold) = (4, 4)
Rotation angle = θ = 30º
Let new ending coordinates of the line after rotation = (Xnew, Ynew).
Xnew
= Xold x cosθ – Yold x sinθ
= 4 x cos30º – 4 x sin30º
= 4 x (√3 / 2) – 4 x (1 / 2)
= 2√3 – 2
= 2(√3 – 1)
= 2(1.73 – 1)
= 1.46
Ynew
Thus, New ending coordinates of the line after rotation = (1.46, 5.46).
Alternatively,
In matrix form, the new ending coordinates of the line after rotation may be obtained as-
Problem-02: review Excel sheet for training
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
Thus, New coordinates of the square after scaling = A (0, 9), B(6, 9), C(6, 0), D(0, 0).
2D Reflection in Computer Graphics-
Reflection On X-Axis:
Problem-01:
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.
Solution-
Given-
Old corner coordinates of the triangle = A (3, 4), B(6, 4), C(5, 6)
Reflection has to be taken on the X axis