Unit-3 2D Transformation
Unit-3 2D Transformation
Transformation means changing some graphics into something else by applying rules. We can
have various types of transformations such as translation, scaling up or down, rotation, shearing,
etc. When a transformation takes place on a 2D plane, it is called 2D transformation.
Transformations play an important role in computer graphics to reposition the graphics on the
screen and change their size or orientation.
Translation
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)
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-
Problem-02:
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. Obtain the new coordinates of the square.
Solution-
•Old coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
•Translation vector = (Tx, Ty) = (1, 1)
Consider a point object O has to be rotated from one angle to another in a 2D plane.
Let-
Given a line segment with starting point as (0, 0) and ending point as (4, 4). Apply 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).
Applying the rotation equations, we have-
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º
For Coordinates A(0, 0)
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
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
For Coordinates A(0, 3)
Let-
•Initial coordinates of the object O = (Xold, Yold)
•New coordinates of the reflected object O after reflection = (Xnew, Ynew)
Reflection On X-Axis:
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
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 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-
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-
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-
The primary use of clipping in computer graphics is to remove objects, lines, or line segments that
are outside the viewing pane. The viewing transformation is insensitive to the position of points
relative to the viewing volume − especially those points behind the viewer − and it is necessary to
remove these points before generating the view.
Point Clipping
Line Clipping
The concept of line clipping is same as point clipping. In line clipping, we will cut the portion of line
which is outside of window and keep only the portion that is inside the window.
Various techniques are used to provide text clipping in a computer graphics. It depends on the
methods used to generate characters and the requirements of a particular application. There are
three methods for text clipping which are listed below −
•All or none string clipping
•All or none character clipping
•Text clipping