Professional Documents
Culture Documents
GM Unit 2
GM Unit 2
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.
Homogenous Coordinates
To perform a sequence of transformation such as translation followed by rotation and scaling, we need to follow
a sequential process −
Translation
A translation moves an object to a different position on the screen. You can translate a point in 2D by adding
translation coordinate (t x, ty) to the original coordinate X,Y to get the new coordinate X′,Y′.
1
X’ = X + tx
Y’ = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above equations can also be represented using
the column vectors.
P=[X][Y] p' = [X′][Y′]T = [tx][ty]
We can write it as −
P’ = P + T
Rotation
In rotation, we rotate the object at particular angle θ theta from its origin. From the following figure, we can see
that the point PX,Y is located at angle φ from the horizontal X coordinate with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you will get a new point
P’ X′,Y′.
Using standard trigonometric the original coordinate of point PX,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,
[X′Y′]=[XY][cosθsinθ−sinθcosθ]OR
P’ = P . R
Where R is the rotation matrix
R=[cosθsinθ−sinθcosθ]
The rotation angle can be positive and negative.
For positive rotation angle, we can use the above rotation matrix. However, for negative angle rotation, the
matrix will change as shown below −
R=[cos(−θ)sin(−θ)−sin(−θ)cos(−θ)]
=[cosθ−sinθsinθcosθ](∵cos(−θ)=cosθandsin(−θ)=−sinθ)
2
Scaling
To change the size of an object, scaling transformation is used. In the scaling process, you either expand or
compress the dimensions of the object. Scaling can be achieved by multiplying the original coordinates of the
object with the scaling factor to get the desired result.
Let us assume that the original coordinates are X,Y, the scaling factors are (SX, SY), and the produced coordinates
are X′,Y′. This can be mathematically represented as shown below −
X' = X . SX and Y' = Y . SY
The scaling factor SX, SY scales the object in X and Y direction respectively. The above equations can also be
represented in matrix form as below −
(X′Y′)=(XY)[Sx00Sy]
OR
P’ = P . S
Where S is the scaling matrix. The scaling process is shown in the following figure.
If we provide values less than 1 to the scaling factor S, then we can reduce the size of the object. If we provide
values greater than 1, then we can increase the size of the object.
Reflection
Reflection is the mirror image of original object. In other words, we can say that it is a rotation operation with
180°. In reflection transformation, the size of the object does not change.
The following figures show reflections with respect to X and Y axes, and about the origin respectively.
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.
3
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.
Composite Transformation
If a transformation of the plane T1 is followed by a second plane transformation T2, then the result itself may be
represented by a single transformation T which is the composition of T1 and T2 taken in that order. This is
written as T = T1∙T2.
Composite transformation can be achieved by concatenation of transformation matrices to obtain a combined
transformation matrix.
A combined matrix −
[T][X] = [X] [T1] [T2] [T3] [T4] …. [Tn]
Where [Ti] is any combination of
Translation
Scaling
4
Shearing
Rotation
Reflection
The change in the order of transformation would lead to different results, as in general matrix multiplication is
not cumulative, that is [A] . [B] ≠ [B] . [A] and the order of multiplication. The basic purpose of composing
transformations is to gain efficiency by applying a single composed transformation to a point, rather than
applying a series of transformation, one after another.
2- Dimensional Transformations
The Basic Transformations:
1. Translation
2. Scaling
3. Rotation
Other Transformations:
1. Reflection
2. Shearing
Translations
Displacement of an object in a given distance and direction from its original position.
5
The translation pair (tx, ty) is called a translation vector or shift vector
A translation can also be represented by a pair of numbers, t=(t x,ty) where tx is the change in
the x-coordinate and tyis the change in y coordinate. To translate the point p by t, we simply
add to obtain the new (translated) point.
Rotation
Example of Rotation
Scaling
6
Example for Scaling
Reflection
A reflection is a transformation that produces a mirror image of an object Generated relativeto an axis of
reflection
7
Shearing
A transformation that distorts the shape of an object such that the transformed object appears as if
the object were composed of internal layers that had been caused to slide over each other.
2D VIEWING
8
Fig 2.10 Steps involved with window to viewport mapping
9
window and viewport
To maintain the same relative placement in view port as in window. The conversion is performed
with the following sequence of transformations:
1. Perform a scaling transformation using point position of (xw min, yw min) that scales the
window area to the size of view port.
2. Translate the scaled window area to the position of view port. Relative proportions of
objects are maintained if scaling factor are the same(Sx=Sy).
10
Advantages
1. The position of the viewport can be changed allowing objects to be viewed at different
positions on the Interface Window.
2. Multiple viewports can also be used to display different sections of a scene at different
screen positions. Also, by changing the dimensions of the viewport, the size and proportions
of the objects being displayed can be manipulated.
3. Thus, a zooming affect can be achieved by successively mapping different dimensioned
clipping windows on a fixed sized viewport.
4. If the aspect ratio of the world window and the viewport are different, then the image may
look distorted.
2D viewing functions
11
CLIPPING OPERATION
1. Point Clipping
2. Line Clipping
3. Area Clipping
4. Curve Clipping
5. Text Clipping
1. Point Clipping
In computer graphics our screen act as a 2-D coordinate system. it is not necessary that each and
every point can be viewed on our viewing pane(i.e. our computer screen). We can view points,
which lie in particular range (0,0) and (Xmax, Ymax). So, clipping is a procedure that identifies
those portions of a picture that are either inside or outside of our viewing pane.
In case of point clipping, we only show/print points on our window which are in range of our
viewing pane, others points which are outside the range are discarded.
2. LINE CLIPPING
Clipping window
Cohen-Sutherland algorithm divides a two-dimensional space into 9 regions and then efficiently
determines the lines and portions of lines that are inside the given rectangular area.
13
2. For identifying the visible and invisible area in the 3D object.
3. For creating objects using solid modeling.
4. For drawing operations.
5. Operations related to the pointing of an object.
ii) For deleting, copying, moving part of an object.
2. LIANG-BARSKY LINE CLIPPING
Based on analysis of parametric equation of a line segment, faster line clippers have been
developed, which can be written in the form :
x = x1 + u ∆x
y = y1 + u ∆y where 0<=u<=1 and where ∆x = (x2 - x1) and ∆y = (y2 - y1)
In the Liang-Barsky approach we first the point clipping condition in parametric form
xwmin <= x1 + u ∆x <=. xwmax
ywmin <= y1 + u ∆y <= ywmax
3. POLYGON CLIPPING
An algorithm that clips a polygon is rather complex. Each edge of the polygon must be tested
against each edge of the clipping window, usually a rectangle. As a result, new edges may be
added, and existing edges may be discarded, retained, or divided. Multiple polygons may result
from clipping a single polygon. We need an organized way to deal with all of these cases.
The Sutherland and Hodgman's polygon clipping algorithm is used in this tool. This algorithm is
based on a divide- and-conquer strategy that solves a series of simple and identical problems
that, when combined, solve the overall problem. The simple problem is to clip a polygon against
a single infinite clipping edge. This process outputs the series of vertices that define the clipped
polygon. Four clipping edges, each defining one boundary of the clipping window, are used to
successively to fully clip the polygon.
Area clipping
1. Both vertices are inside : Only the second vertex is added to the output list
14
2. First vertex is outside while second one is inside : Both the point of intersection of the
edge with the clip boundary and the second vertex are added to the output list
3. First vertex is inside while second one is outside : Only the point of intersection of the
edge with the clip boundary is added to the output list
15
4. Both vertices are outside : No vertices are added to the output list
Polygon Clipping
5. Curve Clipping
Curve Clipping involves complex procedures as compared to line clipping. Curve clipping requires
more processing than for object with linear boundaries. Consider window which is rectangular in
shape. The circle is to consider against rectangle window.
If circle is completely inside boundary of the window, it is considered visible. So save the circle. If
a circle is in outside window, discard it. If circle cut the boundary then consider it to be clipping
case.
The below figure illustrates circle clipping against a rectangular window. On the first pass, we can
clip the bounding rectangle of the object against the bounding rectangle of the clip region. If the
two regions overlap, we will need to solve the simultaneous line-curve equations to obtain the
clipping intersection points
16
5. 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 −
In all or none string clipping method, either we keep the entire string or we reject entire string based
on the clipping window. As shown in the above figure, STRING2 is entirely inside the clipping
window so we keep it and STRING1 being only partially inside the window, we reject.
The following figure shows all or none character clipping −
17
Fig 2.23 Text Clipping Example -2
This clipping method is based on characters rather than entire string. In this method if the string is
entirely inside the clipping window, then we keep it. If it is partially outside the window, then −
You reject only the portion of the string being outside
If the character is on the boundary of the clipping window, then we discard that entire
character and keep the rest string.
The following figure shows text clipping −
18
This clipping method is based on characters rather than the entire string. In this
method if the string is entirely inside the clipping window, then we keep it. If it is
partially outside the window, then
You reject only the portion of string being outside.
If the character is on the boundary of the clipping window, then we
discard only that portionof character that is outside of the clipping
window.
19