0% found this document useful (0 votes)
70 views55 pages

Unit-3 2D Transformation

The document discusses various 2D transformations including translation, rotation, scaling, and reflection. Translation moves an object by adding a translation vector to the original coordinates. Rotation uses trigonometric functions like cosine and sine to calculate new coordinates based on an angle of rotation. Scaling multiplies the original coordinates by scaling factors to increase or decrease size. Reflection produces a mirror image of an object across an axis by changing the sign of coordinates on one axis. Examples demonstrate applying each transformation to geometric objects and finding the new coordinates.

Uploaded by

fatma taqvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views55 pages

Unit-3 2D Transformation

The document discusses various 2D transformations including translation, rotation, scaling, and reflection. Translation moves an object by adding a translation vector to the original coordinates. Rotation uses trigonometric functions like cosine and sine to calculate new coordinates based on an angle of rotation. Scaling multiplies the original coordinates by scaling factors to increase or decrease size. Reflection produces a mirror image of an object across an axis by changing the sign of coordinates on one axis. Examples demonstrate applying each transformation to geometric objects and finding the new coordinates.

Uploaded by

fatma taqvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

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

2D Translation is a process of moving an object from one position to another in a two


dimensional 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)

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)

•The homogeneous coordinates representation


of (X, Y) is (X, Y, 1).
•Through this representation, all the
transformations can be performed using matrix
/ vector multiplications.

The above translation matrix may be


represented as a 3 x 3 matrix as-
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-
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)

For Coordinates A(0, 3)

Let the new coordinates of corner A = (Xnew, Ynew).

Applying the translation equations, we have-


•Xnew = Xold + Tx = 0 + 1 = 1
•Ynew = Yold + Ty = 3 + 1 = 4

Thus, New coordinates of corner A = (1, 4).


For Coordinates B(3, 3)

Let the new coordinates of corner B = (Xnew, Ynew).

Applying the translation equations, we have-


•Xnew = Xold + Tx = 3 + 1 = 4
•Ynew = Yold + Ty = 3 + 1 = 4

Thus, New coordinates of corner B = (4, 4).

For Coordinates C(3, 0)

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

Applying the translation equations, we have-


•Xnew = Xold + Tx = 3 + 1 = 4
•Ynew = Yold + Ty = 0 + 1 = 1

Thus, New coordinates of corner C = (4, 1).


For Coordinates D(0, 0)

Let the new coordinates of corner D = (Xnew, Ynew).


Applying the translation equations, we have-
•Xnew = Xold + Tx = 0 + 1 = 1
•Ynew = Yold + Ty = 0 + 1 = 1

Thus, New coordinates of corner D = (1, 1).


Thus, New coordinates of the square = A (1, 4), B(4, 4), C(4, 1), D(1, 1).
Rotation
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θ

In Matrix form, the above rotation equations may be


represented as-

For homogeneous coordinates, the above rotation matrix


may be represented as a 3 x 3 matrix as-
Problem-01:

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-

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).
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º
For Coordinates A(0, 0)

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

Applying the rotation equations, we have-

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

Thus, New coordinates of corner A after rotation = (0, 0).


For Coordinates B(1, 0)

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

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

Thus, New coordinates of corner B after rotation = (0, 1).


For Coordinates C(1, 1)

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

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

Thus, New coordinates of corner C after rotation = (-1, 1).


Thus, New coordinates of the triangle after rotation = A (0, 0), B(0, 1), C(-1, 1).
Scaling

In computer graphics, 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.

Consider a point object O has to be scaled in a 2D plane.


Let-
•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 x Sx
•Ynew = Yold x Sy

In Matrix form, the above scaling equations may be


represented as-

For homogeneous coordinates, the above scaling matrix


may be represented as a 3 x 3 matrix as-
Problem-01:

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 the new coordinates of corner A after scaling = (Xnew, Ynew).

Applying the scaling equations, we have-


•Xnew = Xold x Sx = 0 x 2 = 0
•Ynew = Yold x Sy = 3 x 3 = 9

Thus, New coordinates of corner A after scaling = (0, 9).

For Coordinates B(3, 3)

Let the new coordinates of corner B after scaling = (Xnew, Ynew).

Applying the scaling equations, we have-


•Xnew = Xold x Sx = 3 x 2 = 6
•Ynew = Yold x Sy = 3 x 3 = 9

Thus, New coordinates of corner B after scaling = (6, 9).


For Coordinates C(3, 0)

Let the new coordinates of corner C after scaling = (Xnew, Ynew).

Applying the scaling equations, we have-


•Xnew = Xold x Sx = 3 x 2 = 6
•Ynew = Yold x Sy = 0 x 3 = 0

Thus, New coordinates of corner C after scaling = (6, 0).

For Coordinates D(0, 0)

Let the new coordinates of corner D after scaling = (Xnew, Ynew).

Applying the scaling equations, we have-


•Xnew = Xold x Sx = 0 x 2 = 0
•Ynew = Yold x Sy = 0 x 3 = 0

Thus, New coordinates of corner D after scaling = (0, 0).


Thus, New coordinates of the square after scaling = A (0, 9), B(6, 9), C(6, 0), D(0, 0).
Reflection

•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.
Consider a point object O has to be reflected in a 2D plane.

Let-
•Initial coordinates of the object O = (Xold, Yold)
•New coordinates of the reflected object O after reflection = (Xnew, Ynew)
Reflection On X-Axis:

This reflection is achieved by using the following


reflection equations-
•Xnew = Xold
•Ynew = -Yold

In Matrix form, the above reflection equations may be


represented as-

For homogeneous coordinates, the above reflection matrix


may be represented as a 3 x 3 matrix as-
Reflection On Y-Axis:

This reflection is achieved by using the following reflection


equations-
•Xnew = -Xold
•Ynew = Yold

In Matrix form, the above reflection equations may be


represented as-

For homogeneous coordinates, the above reflection matrix


may be represented as a 3 x 3 matrix as-
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

For Coordinates A(3, 4)

Let the new coordinates of corner A after reflection = (Xnew, Ynew).


Applying the reflection equations, we have-
•Xnew = Xold = 3
•Ynew = -Yold = -4

Thus, New coordinates of corner A after reflection = (3, -4).


For Coordinates B(6, 4)

Let the new coordinates of corner B after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = Xold = 6
•Ynew = -Yold = -4

Thus, New coordinates of corner B after reflection = (6, -4).

For Coordinates C(5, 6)

Let the new coordinates of corner C after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = Xold = 5
•Ynew = -Yold = -6

Thus, New coordinates of corner C after reflection = (5, -6).


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

For Coordinates A(3, 4)

Let the new coordinates of corner A after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = -Xold = -3
•Ynew = Yold = 4

Thus, New coordinates of corner A after reflection = (-3, 4).


For Coordinates B(6, 4)

Let the new coordinates of corner B after reflection = (Xnew, Ynew).


Applying the reflection equations, we have-
•Xnew = -Xold = -6
•Ynew = Yold = 4

Thus, New coordinates of corner B after reflection = (-6, 4).


For Coordinates C(5, 6)

Let the new coordinates of corner C after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = -Xold = -5
•Ynew = Yold = 6

Thus, New coordinates of corner C after reflection = (-5, 6).


Thus, New coordinates of the triangle after reflection = A (-3, 4), B(-6, 4), C(-5, 6).
Shearing

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-

Consider a point object O has to be sheared in a 2D plane.

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 X axis is achieved by using the following


shearing equations-
•Xnew = Xold + Shx x Yold
•Ynew = Yold

In Matrix form, the above shearing equations may be


represented as-

For homogeneous coordinates, the above


shearing matrix may be represented as a 3 x 3
matrix as-
Shearing in Y Axis-

Shearing in Y axis is achieved by using the following


shearing equations-
•Xnew = Xold
•Ynew = Yold + Shy x Xold

In Matrix form, the above shearing equations may be


represented as-

For homogeneous coordinates, the above shearing matrix


may be represented as a 3 x 3 matrix as-
Problem-01:

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-

For Coordinates A(1, 1)

Let the new coordinates of corner A after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
•Ynew = Yold = 1

Thus, New coordinates of corner A after shearing = (3, 1).


For Coordinates B(0, 0)

Let the new coordinates of corner B after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0
•Ynew = Yold = 0

Thus, New coordinates of corner B after shearing = (0, 0).


For Coordinates C(1, 0)

Let the new coordinates of corner C after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1
•Ynew = Yold = 0

Thus, New coordinates of corner C after shearing = (1, 0).


Thus, New coordinates of the triangle after shearing in X axis = A (3, 1), B(0, 0), C(1, 0).
Shearing in Y Axis-

For Coordinates A(1, 1)

Let the new coordinates of corner A after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold = 1
•Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3

Thus, New coordinates of corner A after shearing = (1, 3).

For Coordinates B(0, 0)

Let the new coordinates of corner B after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold = 0
•Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0

Thus, New coordinates of corner B after shearing = (0, 0).


For Coordinates C(1, 0)

Let the new coordinates of corner C after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•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).
Viewing & Clipping

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.

Cohen-Sutherland Line Clippings


We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom, Right, and Left of
the region as shown in the following figure. Here, the TOP and LEFT bit is set to 1 because it is the TOP-
LEFT corner.
Polygon Clipping Sutherland Hodgman Algorithm

A polygon can also be clipped by specifying


the clipping window. Sutherland Hodgeman
polygon clipping algorithm is used for
polygon clipping. In this algorithm, all the
vertices of the polygon are clipped against
each edge of the clipping window.
First the polygon is clipped against the left
edge of the polygon window to get new
vertices of the polygon. These new vertices
are used to clip the polygon against right
edge, top edge, bottom edge, of the clipping
window as shown in the following figure.
While processing an edge of a polygon with clipping window, an intersection point is found if edge is not
completely inside clipping window and the a partial edge from the intersection point to the outside edge
is clipped. The following figures show left, right, top and bottom edge clippings −
Text Clipping

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

You might also like