Computer Graphics Unit-2
Computer Graphics Unit-2
Transformation Techniques-
In computer graphics, various transformation techniques are-
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shear
2D Translation
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 = (Xnew, Ynew)
● Translation vector or Shift vector = (Tx, Ty)
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)
In Matrix form, the above translation equations may be represented as-
PRACTICE PROBLEMS BASED ON 2D TRANSLATION
Problem-01:
Given a circle C with radius 10 and center coordinates (1, 4). Apply the translation with
distance 5 towards X axis and 1 towards 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)
Solution-
Given-
● Old coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
● Translation vector = (Tx, Ty) = (1, 1)
2D Rotation
In Computer graphics, 2D Rotation is a process of rotating an object with respect to an
angle in a two dimensional plane.
Consider a point object O has to be rotated from one angle to another in a 2D plane.
Let-
● 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 x cosθ – Yold x sinθ
● Ynew = Xold x sinθ + Yold x cosθ
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
= Xold x sinθ + Yold x cosθ
= 4 x sin30º + 4 x cos30º
= 4 x (1 / 2) + 4 x (√3 / 2)
= 2 + 2√3
= 2(1 + √3)
= 2(1 + 1.73)
= 5.46
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-
Thus, New ending coordinates of the line after rotation = (1.46, 5.46).
Problem-02:
Given a triangle with corner coordinates (0, 0), (1, 0) and (1, 1). Rotate the triangle by 90
degree anticlockwise direction and find out the new coordinates.
Solution-
We rotate a polygon by rotating each vertex of it with the same rotation angle.
Given-
● Old corner coordinates of the triangle = A (0, 0), B(1, 0), C(1, 1)
● Rotation angle = θ = 90º
Xnew
= Xold x cosθ – Yold x sinθ
= 0 x cos90º – 0 x sin90º
=0
Ynew
= Xold x sinθ + Yold x cosθ
= 0 x sin90º + 0 x cos90º
=0
Xnew
= Xold x cosθ – Yold x sinθ
= 1 x cos90º – 0 x sin90º
=0
Ynew
= Xold x sinθ + Yold x cosθ
= 1 x sin90º + 0 x cos90º
=1+0
=1
Xnew
= Xold x cosθ – Yold x sinθ
= 1 x cos90º – 1 x sin90º
=0–1
= -1
Ynew
= Xold x sinθ + Yold x cosθ
= 1 x sin90º + 1 x cos90º
=1+0
=1
2D Scaling
In computer graphics, scaling is a process of modifying or altering the size of objects.
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.
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
2D Reflection
Reflection deals with obtaining a mirror image of the 2D object.
● 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.
Let-
● Initial coordinates of the object O = (Xold, Yold)
● New coordinates of the reflected object O after reflection = (Xnew, Ynew)
Reflection On X-Axis:
Reflection On Y-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
Thus, New coordinates of the triangle after reflection = A (3, -4), B(6, -4), C(5, -6).
Problem-02:
Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection on the Y
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 Y axis
2D Shearing
In Computer graphics, 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-
1. Shearing in X direction
2. Shearing in Y direction
Let-
● 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-
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-
Given-
● 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-
Shearing in Y Axis-
● Xnew = Xold = 1
● Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2
● Thus, New coordinates of corner 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).
In order to maintain the same relative placement of the point in the viewport as in the
window, we require:
Solving these impressions for the viewport position (xv, yv), we have
xv=xvmin+(xw-xwmin)sx
yv=yvmin+(yw-ywmin)sy ……………………………...........equation 2
Equation (1) and Equation (2) can also be derived with a set of transformation that
converts the window or world coordinate area into the viewport or screen coordinate area.
From normalized coordinates, object descriptions are mapped to the various display
devices.
Any number of output devices can we open in a particular app, and three windows to
viewport transformation can be performed for each open output device.
This mapping called workstation transformation (It is accomplished by selecting a window
area in normalized space and a viewport area in the coordinates of the display device).
Viewing Transformation= T * S * T1