05 Transformation
05 Transformation
05 Transformation
Transformation
2D Transformation in Computer Graphics-
In Computer graphics,
Transformation is a process of modifying and re-
positioning the existing graphics.
2
Transformation Techniques-
3
Translation
It is the straight line movement of an object from one position to another is called
Translation. Here the object is positioned from one coordinate location to another.
The pair (tx, ty) is called the translation vector or shift vector.
4
Matrix for Translation:
We can write it as −
P’ = P + T
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)
8
The OpenGL function is glTranslatef( tx, ty, tz );
9
Rotation
Rotation refers to mathematical operation in which the graphical object is rotated about an angle (θ)
to the axis.
Rotation is of two types: anti-clockwise and clockwise rotation.
Suppose we want to rotate a point with coordinates A (x1, y1) clockwise through an angle θ about the
origin
Then the new coordinates A’ (x2, y2):
x2 = x1 cosθ + y1 sinθ
y2 = x1 sinθ - y1 cosθ
10
Using standard trigonometric the original coordinate of point P(X,Y) can be represented as −
X=rcosϕ......(1)
Y=rsinϕ......(2)
Same way we can represent the point P’ (X′,Y′) as −
x′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ.......(3)
y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ.......(4)
Substituting equation 1 & 2 in 3 & 4 respectively, we will get
x′=xcosθ−ysinθ
y′=xsinθ+ycosθ
Representing the above equation in matrix form, Matrix for homogeneous co-ordina
rotation (anticlockwise)
P’ = P . R
Where R is the rotation matrix
Matrix for homogeneous co-ordinate rotation (clockwise)
11
P’ = P . R
Where A is angle 14
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.
It is used to alter or change the size of objects. The change is done using scaling
factors. There are two scaling factors, i.e. Sx in x direction Sy in y-direction. If the
original position is x and y. Scaling factors are Sx and Sy then the value of coordinates
after scaling will be x1 and y1.
If the picture to be enlarged to twice its original size then Sx = Sy =2. If Sxand Sy are
not equal then scaling will occur but it will elongate or distort the picture. 15
This can be mathematically represented as shown below
−
X' = X . SX and Y' = Y . SY
P’ = P . S
16
P’ = P . S
17
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 C(3, 0) Thus, New coordinates of corner D after scaling = (0, 0).
It is a transformation which produces a mirror image of an object. The mirror image can
be either about x-axis or y-axis. The object is rotated by180°.
Types of Reflection:
1.Reflection about the x-axis
2.Reflection about the y-axis
3.Reflection about an axis perpendicular to xy
plane and passing through the origin
4.Reflection about line y=x
21
1. Reflection about x-axis: The object can be reflected about x-axis with the help of the
following matrix
In this transformation value of x will remain same whereas the value of y will become negative.
Following figures shows the reflection of the object axis. The object will lie another side of the x-
axis.
Here the values of x will be reversed, whereas the value of y will remain the same. The object will
lie another side of the y-axis.
23
3. Reflection about an axis perpendicular to xy plane and passing through origin:
In the matrix of this transformation is given below
24
4. Reflection about line y=x: The object may be reflected about line y = x with the help of
following transformation matrix
9/3/20XX 26
The a point coordinates after reflection
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
9/3/20XX 28
For Coordinates B(6, 4)
9/3/20XX 30
Shear
A transformation that slants the shape of an object is called the shear transformation. There are two
shear transformations X-Shear and Y-Shear. One shifts X coordinates values and other shifts Y
coordinate values. However; in both the cases only one coordinate changes its coordinates and
other preserves its values. Shearing is also termed as Skewing.
X-Shear
The X-Shear preserves the Y coordinate and changes are made to X coordinates, which causes the vertical lines
to tilt right or left as shown in below figure.
31
The transformation matrix for X-Shear can be represented as −
Y-Shear
The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the horizontal lines to
transform into lines which slopes up or down as shown in the following figure.
9/3/20XX 33
Problem-01:
Given a 3D triangle with points (0, 0, 0), (1, 1, 2) and (1, 1, 3). Apply shear parameter 2 on X axis, 2 on Y axis and 3 on Z axis
and find out the new coordinates of the object.
Solution-
Given-
•Old corner coordinates of the triangle = A (0, 0, 0), B(1, 1, 2), C(1, 1, 3)
•Shearing parameter towards X direction (Shx) = 2
•Shearing parameter towards Y direction (Shy) = 2
•Shearing parameter towards Y direction (Shz) = 3
Shearing in X Axis-
34
For Coordinates A(0, 0, 0)
Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).
Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).
Shearing in Y Axis-
Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).
Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).
Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).
The method of selecting and enlarging a portion of a drawing is called windowing. The area
chosen for this display is called a window. The window is selected by world-coordinate.
Sometimes we are interested in some portion of the object and not in full object. So we will
decide on an imaginary box. This box will enclose desired or interested area of the object.
Such an imaginary box is called a window.
Viewport: An area on display device to which a window is mapped [where it is to
displayed].
Basically, the window is an area in object space. It encloses the object. After the user
selects this, space is mapped on the whole area of the viewport. Almost all 2D and 3D
graphics packages provide means of defining viewport size on the screen. It is possible to
determine many viewports on different areas of display and view the same object in a
39
different angle in each viewport.
Viewing Transformations – mapping part of a world coordinate scene to
device coordinates is called viewing transformation Window-Viewport
Mapping
First, we construct the scene in world coordinate using the output primitives and
attributes.
To obtain a particular orientation, we can set up a 2-D viewing coordinate system in the
Once the viewing frame is established, are then transform description in world coordinates
to viewing coordinates.
Then, we define viewport in normalized coordinates (range from 0 to 1) and map the
At the final step, all parts of the picture that (i.e., outside the viewport are dipped, and the
Once object description has been transmitted to the viewing reference frame, we
choose the window extends in viewing coordinates and selects the viewport limits in
normalized coordinates.
Object descriptions are then transferred to normalized device coordinates:
We do this thing using a transformation that maintains the same relative placement of
an object in normalized space as they had in viewing coordinates.
If a coordinate position is at the center of the viewing window:
It will display at the center of the viewport.
Fig shows the window to viewport mapping. A point at position (xw, yw) in window
mapped into position (xv, yv) in the associated viewport.
43
In order to maintain the same relative placement of the point in the viewport as in the window,
we require:
44
Solving these impressions for the viewport position (xv, yv), we have
xv=xvmin+(xw-xwmin)sx
yv=yvmin+(yw-ywmin)sy ...........equation 2
9/3/20XX 45
9/3/20XX Presentation Title 46
9/3/20XX Presentation Title 47
9/3/20XX Presentation Title 48
9/3/20XX Presentation Title 49
9/3/20XX Presentation Title 50
9/3/20XX Presentation Title 51