0% found this document useful (0 votes)
56 views

CS401-M3-Computer Graphics-Ktustudents - in

The document discusses two-dimensional geometric transformations including translation, rotation, scaling, reflection, and shearing. It provides the mathematical definitions and transformation matrices for each type of transformation. Homogeneous coordinates are also introduced as a way to represent points in 3D to allow multiple transformations to be applied through matrix multiplication.

Uploaded by

Vic
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)
56 views

CS401-M3-Computer Graphics-Ktustudents - in

The document discusses two-dimensional geometric transformations including translation, rotation, scaling, reflection, and shearing. It provides the mathematical definitions and transformation matrices for each type of transformation. Homogeneous coordinates are also introduced as a way to represent points in 3D to allow multiple transformations to be applied through matrix multiplication.

Uploaded by

Vic
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/ 30

MEA Engineering College

Module-3
Two dimensional transformations. Homogeneous coordinate systems – matrix formulation and
concatenation of transformations. Windowing concepts –Window to Viewport Transformation-
Two dimensional clipping-Line clipping – Cohen Sutherland, Midpoint Subdivision algorithm
Two Dimensional Geometric Transformations:
Changes in orientations, size and shape are accomplished with geometric transformations that alter the
coordinate description of objects.

Basic transformation

Translation
 T(tx, ty)
 Translation
distances
Scale
 S(sx,sy)
 Scale factors
Rotation
 R( )

KTUStudents.in
 Rotation angle
Translation
A translation is applied to an object by representing it along a straight line path from one
coordinate location to another adding translation distances, tx, ty to original coordinate position (x,y) to
move the point to a new position (x’,y’) to

x’ = x + tx, y’ = y + ty

Dept. of CSE 1

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College
The translation distance point (tx,ty) is called translation vector or shift vector.

Translation equation can be expressed as single matrix equation by using column vectors to represent the
coordinate position and the translation vector as

P (x, y)
T (tx , t y )

x' x t x
y' y ty
The translation distance point (tx,ty) is called translation vector or shift vector.

Translation equation can be expressed as single matrix equation by using column vectors
to represent the coordinate position and the translation vector as
P  (x, y)
T  (tx ,ty )

x'  x  tx
y'  y  ty

KTUStudents.in x1
y1
x tx
= y + ty

P'  P  T

Dept. of CSE For more study materials: WWW.KTUSTUDENTS.IN 2


MEA Engineering College

Moving a polygon from one position to another position


with the translation vector (-5.5, 3.75)

Rotations:

A two-dimensional rotation is applied to an object by repositioning it along a


circular path on xy plane. To generate a rotation, specify a rotation angle θ and the
position (xr,yr) of the rotation point (pivot point) about which the object is to be rotated.

Positive values for the rotation angle define counter clock wise rotation about
pivot point. Negative value of angle rotates objects in clock wise direction. The

KTUStudents.in
transformation can also be described as a rotation about a rotation axis perpendicular to
xy plane and passes through pivot point

Rotation of a point from position (x,y) to position (x’,y’) through angle θ relative to
coordinateorigin

Dept. of CSE For more study materials: WWW.KTUSTUDENTS.IN 3


MEA Engineering College

The transformation equations for rotation of a point position P when the pivot point is at
coordinate origin. In figure r is constant distance of the point positions Ф is the original
angular of the point from horizontal and θ is the rotation angle.

The transformed coordinates in terms of angle θ and Ф

x’ = rcos(θ+Ф) = rcosθ cosФ – rsinθsinФ

y’ = rsin(θ+Ф) = rsinθ cosФ + rcosθsinФ

The original coordinates of the point in polar coordinates

x = rcosФ, y = rsinФ

the transformation equation for rotating a point at position (x,y) through an angle θ about
origin

x’ = xcosθ – ysinθ

KTUStudents.in
y’ = xsinθ + ycosθ

Rotation equation

P’= R . P

Rotation Matrix

R= Cosθ sinθ
Sinθ cosθ

Dept. of CSE For more study materials: WWW.KTUSTUDENTS.IN 4


MEA Engineering College

 x' cos  sinx


 y'  sin  cos  y
    

Note : Positive values for the rotation angle define counterclockwise rotations about the
rotation point and negative values rotate objects in the clockwise.

Scaling
A scaling transformation alters the size of an object. This operation can be carried out for
polygons by multiplying the coordinate values (x,y) to each vertex by scaling factor Sx &
Sy to produce the transformed coordinates (x’,y’)

x’= x.Sx y’ = y.Sy

scaling factor Sx scales object in x direction while Sy scales in ydirection.

The transformation equation in matrix form

KTUStudents.in
x1 sx 0
 x y
y1  sy

or

P’ = S. P

Where S is 2 by 2 scaling matrix

Turning a square (a) Into a rectangle (b) with scaling factors sx = 2 and sy= 1.

Any positive numeric values are valid for scaling factors sx and sy. Values less than 1
reduce the size of the objects and values greater than 1 produce an enlarged object.
There are two types of Scaling. They are

Uniform scaling
Non Uniform Scaling

Dept. of CSE For more study materials: WWW.KTUSTUDENTS.IN 5


To get uniform scaling it is necessary to assign same value for sx and sy. Unequal values
for sx and sy result in a non uniform scaling.
Other Transformations

1. Reflection
2. Shear

Reflection

A reflection is a transformation that produces a mirror image of an object. The mirror


image for a two-dimensional reflection is generated relative to an axis of reflection by
rotating the object 180o about the reflection axis. We can choose an axis of reflection in
the xy plane or perpendicular to the xy plane or coordinate origin

Reflection of an object about the x axis

KTUStudents.in
Reflection the x axis is accomplished with the transformation matrix

1 0 0

0 -1 0

0 0 1

Reflection of an object about the y axis

Dept. of CSE For more study materials: WWW.KTUSTUDENTS.IN 6


Reflection the y axis is accomplished with the transformation matrix

-1 0 0

0 1 0

0 0 1

Reflection of an object about the coordinate origin

KTUStudents.in
Reflection about origin is accomplished with the transformation matrix

-1 0 0

0 -1 0

0 0 1

Shear

A Transformation that slants the shape of an object is called the shear transformation.
Two common shearing transformations are used. One shifts x coordinate values and other
shift y coordinate values. However in both the cases only one coordinate (x or y) changes
its coordinates and other preserves its values.

Dept. of CSE For more study materials: WWW.KTUSTUDENTS.IN 7


The x shear preserves the y coordinates, but changes the x values which cause vertical
lines to tilt right or left as shown in figure

The Transformations matrix for x-shear is

1 shx 0
0 1 0
0 0 1

KTUStudents.in
which transforms the coordinates as

x’ =x+ shx .y

y’ = y

Y Shear

The y shear preserves the x coordinates, but changes the y values which cause horizontal
lines which slope up or down

The Transformations matrix for y-shear is


1 0 0
shy 1 0
0 0 1
Which transforms the coordinates

as x’ =x

y’ = y+ shy .x

Dept. of CSE For more study materials: WWW.KTUSTUDENTS.IN 8


MEA Engineering College

1
X
1 shx 0 X
1 = shy 1 0 1 Y
Y 1
0 0 1



which transforms the coordinates as x’

=x+ shx .y

y’ = y+ shy .x

Homogenous Coordinates:
To perform a sequence of transformation such as translation followed by rotation and scaling, we need to
follow a sequential process −

KTUStudents.in
 Translate the coordinates,
 Rotate the translated coordinates, and then
 Scale the rotated coordinates to complete the composite transformation.
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2 transformation matrix. To
convert a 2×2 matrix to 3×3 matrix, we have to add an extra dummy coordinate W.

In this way, we can represent the point by 3 numbers instead of 2 numbers, which is called Homogenous
Coordinate system. In this system, we can represent all the transformation equations in matrix multiplication.
Any Cartesian point P(X, Y) can be converted to homogenous coordinates by P’ (X w, Yw, w).

Translation
A translation moves an object to a different position on the screen. You can translate a point in 2D by adding
translation coordinate (tx, ty) to the original coordinate (X, Y) to get the new coordinate (X’, Y’).

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

From the above figure, you can write that −

KTUStudents.in
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 P(X, 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’).

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

Using standard trigonometric the original coordinate of point P(X, Y) can be represented as −

KTUStudents.in
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θ)

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

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′]=[X Y] Sx 0
0 Sy
OR

P’ = P . S

Where S is the scaling matrix. The scaling process is shown in the following figure.

KTUStudents.in

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.

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

Homogeneous coordinate systems: matrix formulation and concatenation of transformations.

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

Windowing concepts:
 Window: Area selected in world-coordinate for display is called window. It defines what is to be viewed.
 Viewport: Area on a display device in which window image is display (mapped) is called viewport. It defines
where to display.
 In many case window and viewport are rectangle, also other shape may be used as window and viewport.
 In general finding device coordinates of viewport from word coordinates of window is called as viewing
transformation.
 Sometimes we consider this viewing transformation as window-to-viewport transformation but in general it
involves more steps.

KTUStudents.in

Fig: - A viewing transformation using standard rectangles for the window and viewport.
Now we see steps involved in viewing pipeline.

Construct World- Map Viewing


Convert Map
Coordinate Scene Coordinate to
MS WC World- VC NVC Normalized DC
Using Modeling- Normalized Viewing
Coordinate to Viewport to
Coordinate Coordinates using
Viewing Device
Transformations Window-Viewport
Coordinates Coordinates
Specifications

Fig: - 2D viewing pipeline.


 As shown in figure above first of all we construct world coordinate scene using modeling coordinate
transformation.
 After this we convert viewing coordinates from world coordinates using window to viewport transformation.
 Then we map viewing coordinate to normalized viewing coordinate in which we obtain values in between 0 to 1.
 At last we convert normalized viewing coordinate to device coordinate using device driver software which
provide device specification.
 Finally device coordinate is used to display image on display screen.
 By changing the viewport position on screen we can see image at different place on the screen.

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

 By changing the size of the window and viewport we can obtain zoom in and zoom out effect as per
requirement.
 Fixed size viewport and small size window gives zoom in effect, and fixed size viewport and larger window gives
zoom out effect.
 View ports are generally defines with the unit square so that graphics package are more device independent
which we call as normalized viewing coordinate.
Window-To-Viewport Coordinate Transformation:
 Mapping of window coordinate to viewport is called window to viewport transformation.
 We do this using transformation that maintains relative position of window coordinate into viewport.
 That means center coordinates in window must be remains at center position in viewport.
 We find relative position by equation as follow:
xv − xvmin xw − xwmin
=
xvmax − xvmin xwmax − xwmin

yv − yvmin yw − ywmin
=
yvmax − yvmin ywmax − ywmin
 Solving by making viewport position as subject we obtain:
xv = xvmin + (xw − xwmin)sx

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

yv = yvmin + (yw − ywmin)sy


 Where scaling factor are :
xvmax − xvmin
sx =
xwmax − xwmin
yvmax − yvmin
sy =
ywmax − ywmin
 We can also map window to viewport with the set of transformation, which include following sequence of
transformations:
1. Perform a scaling transformation using a fixed-point position of (xWmin,ywmin) that scales the window area to
the size of the viewport.
2. Translate the scaled window area to the position of the viewport.
 For maintaining relative proportions we take (sx = sy). in case if both are not equal then we get stretched or
contracted in either the x or y direction when displayed on the output device.
 Characters are handle in two different way one way is simply maintain relative position like other primitive and
other is to maintain standard character size even though viewport size is enlarged or reduce.
 Number of display device can be used in application and for each we can use different window-to-viewport
transformation. This mapping is called the workstation transformation.

KTUStudents.in

Fig. 3.4: - workstation transformation.


 As shown in figure two different displays devices are used and we map different window-to-viewport on each
one.
Clipping Operations
 Generally, any procedure that identifies those portions of a picture that are either inside or outside of a
specified region of space is referred to as a clipping algorithm, or simply clipping. The region against which an
object is to clip is called a clip window.
 Clip window can be general polygon or it can be curved boundary.
Application of Clipping
 It can be used for displaying particular part of the picture on display screen.

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

 Identifying visible surface in 3D views.


 Antialiasing.
 Creating objects using solid-modeling procedures.
 Displaying multiple windows on same screen.
 Drawing and painting.
2D Clipping:
Point Clipping
 In point clipping we eliminate those points which are outside the clipping window and draw points which are
inside the clipping window.
 Here we consider clipping window is rectangular boundary with edge (xwmin,xwmax,ywmin,ywmax).
 So for finding wether given point is inside or outside the clipping window we use following inequality:
xwnin ≤ x ≤ xwans
ywnin ≤ y ≤ ywans
 If above both inequality is satisfied then the point is inside otherwise the point is outside the clipping window.
Line Clipping
 Line clipping involves several parts. First case is completely inside second case is completely outside and third
case include partially inside or partially outside the clipping window.

KTUStudents.in
P9

Window Window
P4 P10

P2 P2
P8
P1 P1
P5 P6 P5 P6 P8
P3

P7

P7

Before Clipping After Clipping


(a) (b)
Fig: - Line clipping against a rectangular window.
 Line which is completely inside is display completely. Line which is completely outside is eliminated from display.
And for partially inside line we need to calculate intersection with window boundary and find which part is
inside the clipping boundary and which part is eliminated.
 For line clipping several scientists tried different methods to solve this clipping procedure. Some of them are
discuss below.
Cohen-Sutherland Line Clipping
 This is one of the oldest and most popular line-clipping procedures.

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

 In this we divide whole space into nine region and assign 4 bit code to each endpoint of line depending on the
position where the line endpoint is located.

1001 1000 1010

0001 0000 0010

0101 0100 0110

Fig: - Workstation transformation.


 Figure shows code for line end point which is fall within particular area.
 Code is deriving by setting particular bit according to position of area.
Set bit 1: For left side of clipping window.
Set bit 2: For right side of clipping window.

KTUStudents.in
Set bit 3: For below clipping window.
Set bit 4: For above clipping window.
 All bits as mention above are set means 1 and other are 0.
 After assigning code we check both end points code if both endpoint have code 0000 then line is completely
inside.
 If both are not 0000 then we perform logical ending between this two code and check the result if result is non
zero line is completely outside the clipping window.
 Otherwise we calculate the intersection point with the boundary one by one and divide the line into two parts
from intersection point and perform same procedure for both line segments until we get all segments
completely inside or completely outside.
 Draw line segment which are completely inside and eliminate other line segment which found completely
outside.
 Now we discuss how to calculate intersection points with boundary.
 For intersection calculation we use line equation “y = mx + b”.
 For left and right boundary x coordinate is constant for left “x = xwnin” and for right “x = xwnas” .
 We calculate y coordinate of intersection for this boundary by putting values of x as follow:
y = y1 + m(x − x1)
 Similarly fro top and bottom boundary y coordinate is constant for top “y = ywnas” and for bottom “y =
ywnin”.
 We calculate x coordinate of intersection for this boundary by putting values of y as follow:
y − y1
x = x1 +
m

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College

Midpoint Subdivision Algorithm:

Midpoint Subdivision Algorithm By now you know that the Cohen Sutherland algorithm involves calculating
the intersection of the line with the window’s boundaries. However, these calculations can be avoided by
subdividing the line at its midpoint. This subdividing process is repeated until you get the line segment
completely visible or completely invisible. In the Midpoint Subdivision algorithm, the line is first tested for
visibility. If the line is completely outside the window, then it is invisible and is rejected. If the line is visible,
then the line is within the window and is drawn. On the other hand, if the line is partially visible, then it is
subdivided into two parts. Each line segment is again tested for visibility. This subdivision process is repeated
until you get a line segment that is completely visible (inside the window) or completely invisible (outside the
window).

Figure :Midpoint Subdivision

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College
In figure , the line A1 A2 is partially visible. This line is subdivided into two equal parts A1 A3
and A3 A2 (figure (b)). The visibility tests are then applied on these two line segments and
found to be partially visible. Each of the line segments is further divided to obtain the
midpoints A4 and A5 of A1 A3 and A3 A2 respectively (figure (C)). You can observe from
figure (d) that A1 A4 and A5 A2 are completely invisible and hence they are rejected. The
line segment A3 A5 is completely visible while the line segment A4 A3 is partially visible. The
line segment A4 A3 is further subdivided into two equal parts A3 A6 and A6 A4 . Now, the
line segment A6 A3 is completely visible whereas the line segment A4 A6 is partially
visible. The line segment A4 A6 is further subdivided to obtain midpoint A7 . Now, the line
segment A4 A7 is completely invisible and is rejected, and the line segment A7 A6 is
completely visible. Thus, you get a line A7 A5 which falls into category 1 (visible).
The midpoint co-ordinates (xm, ym) of line joining (x1, y1) and (x2, y2) are given by

xm = x1+ x2 / 2

ym = y1 + y2/2
The Midpoint subdivision algorithm is written as below:
1. Read two endpoints of the line: A(x1, y1) and A(x2, y2).
2. Read two regions of the window (left top and right bottom): (Wx1, Wy1 and Wx2 and Wy2).

KTUStudents.in
3. Assign 4-bit region codes for the two endpoints.
Initialize code with bits 0000.
Set Bit 1 if (x < Wx1 )
Set Bit 2 if (x >Wx2 )
Set Bit 3 if (y < Wy1) Set Bit 4 if (y > Wy2)
4. Check for line visibility
(a) If the region codes for both the endpoints of the line are 0000 then
the line is within the window and completely visible.
Go to step 6
(b) If the region codes for endpoints of the line are not 0000 and the
bitwise logical AND is also not 0000, then the line is outside the
window and completely invisible.
Go to step 6
(c) If the region codes for endpoints do not satisfy any of the above
two conditions then that line intersects any one of the window
boundaries, and only a segment of the line inside the window frame
is visible.
5. The partially visible line is divided into two equal parts. Repeat step 3
through 5 until the line is completely visible or completely invisible.
6. Stop.
As Midpoint Subdivision algorithm involves repeated subdivision of the line
segments, it is slower compared to Cohen Sutherland algorithm, which

For more study materials: WWW.KTUSTUDENTS.IN


MEA Engineering College
directly performs the calculations to determine the co- ordinates where the
line intersects the window boundaries.

……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN

You might also like