0% found this document useful (0 votes)
8 views92 pages

2D Geometric Transformations Guide

Uploaded by

motivationsutra5
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)
8 views92 pages

2D Geometric Transformations Guide

Uploaded by

motivationsutra5
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

Two Dimensional

Geometric

Mohan Bhandari (CG)


Transformations
Unit 3

1
Introduction
Basic Transformations
The orientation, size, and shape of the output primitives
are accomplished with geometric transformations that alter the
coordinate descriptions of objects. The basic geometric

Mohan Bhandari (CG)


transformations are translation, rotation, and scaling. Other
transformations that are often applied to objects include
reflection and shear. In these all cases we consider the
reference point is origin so if we have to do these
transformations about any point then we have to shift these
point to the origin first and then perform required operation and
then again shift to that position.
2
Introduction
Basic Transformations
1. Translation

Mohan Bhandari (CG)


2. Rotation
3. Scaling
4. Reflection
5. shearing 3
HOMOGENOUS FORM
Expressing position in homogeneous coordinates allows us to
represent all geometric transformations equation as matrix
multiplications.
( x, y) -------------------- (xh, yh ,h)

Mohan Bhandari (CG)


x= xh / h
y= yh / h
where h is any non zero value
For convenient h=1

(x,y)-------------------------(x, y, 1)
4
1. Translation
A translation is applied to an object by repositioning it along a
straight-line path from one coordinate location to another. We
translate a two-dimensional point by adding translation
distances, tx, and ty, to the original coordinate position (x, y) to
move the point to a new position (x ' , y').

Mohan Bhandari (CG)


x’ = x + tx
y’ = y + ty
where the pair (tx, ty) is called the
translation vector or shift vector.

5
1. Translation
We can write equation as a single matrix equation by using
column vectors to represent coordinate points and translation
vectors. Thus,

Mohan Bhandari (CG)


P’ = P + T
So we can write

In homogeneous representation if position P = (x, y) is translated to


new position P’= (x’, y’) then:

6
2. ROTATION
A two-dimensional rotation is applied to an object by
repositioning it along a circular path in the xy plane. To generate
a rotation, we specify a rotation angle θ and the position (xr , yr)
of the rotation point (or pivot point) about which the object is to
be rotated.

Mohan Bhandari (CG)


+ Value for ‘θ’ define counter-clockwise rotation about a point
- Value for ‘θ’ defines clockwise rotation about a point

7
Mohan Bhandari (CG)
8
Anticlockwise direction

2. ROTATION
At Origin

Coordinates of point ( x,y ) in polar form

Mohan Bhandari (CG)


9
2. ROTATION
In homogeneous co-ordinate
Anticlockwise direction

Mohan Bhandari (CG)


Clockwise direction

-
10
[Link]
A scaling transformation alters the size of an object. This
operation can be carried out for polygons by multiplying the coordinate
values (x, y) of each vertex by scaling factors sx and sy to produce the
transformed coordinates (x', y').
• sx scales object in ‘x’ direction
• sy scales object in ‘y’ direction

Mohan Bhandari (CG)


11
[Link]
Thus, for equation form,
x' = x. sx and
y’ = y. sy

Mohan Bhandari (CG)


• Values greater than 1 for sx , s y produce enlargement
• Values less than 1 for sx , s y reduce size of object
• s x = s y = 1 leaves the size of the object unchanged
• When sx , s y are assigned the same value s x = s y = 3 or 4 etc
12
then a Uniform Scaling is produced
P‘= S.P
[Link]

Mohan Bhandari (CG)


13
4. Reflection
A reflection is a transformation that produces a mirror
image of an object. The mirror image for a 2D reflection is
generated relative to an axis of reflection by rotating the object
180" about the reflection axis. We can choose an axis of
reflection in the xy-plane or perpendicular to the xy plane.

Mohan Bhandari (CG)


When the reflection axis is a line in the xy plane, the rotation
path about this axis is in a plane perpendicular to the xy-plane.
For reflection axes that are perpendicular to the xy-plane, the
rotation path is in the xy plane.

14
4. Reflection
(i) Reflection about x axis or about line y = 0

x
Keeps value same but flips Y value of
coordinate points

Mohan Bhandari (CG)


x’ = x
y’ = -y

Homogeneous co-ordinate

15
4. Reflection
(ii) Reflection about y axis or about line x = 0

Keeps ‘y’ value same but flips x value of


coordinate
points

Mohan Bhandari (CG)


x’ = -x
y’ = y

Homogeneous co-ordinate

16
4. Reflection
(iii) Reflection about origin

Flip both ‘x’ and ‘y’ coordinates of a point

x’ = -x

Mohan Bhandari (CG)


y’ = -y

Homogeneous co-ordinate

17
4. Reflection
(iv) Reflection about line y = x
x’ = y
y’ = x

Mohan Bhandari (CG)


Homogeneous co-ordinate Equivalent to:
• Reflection about x-axis
• Rotate anticlockwise 90˚
OR
• Clockwise rotation 45 ˚ 18
• Reflection with x-axis
• anticlockwise rotation 45 ˚
4. Reflection
(v) Reflection about line y = -x
x’ = -y
y’ = -x

Mohan Bhandari (CG)


19
5. Shearing
It distorts the shape of object in either ‘x’ or ‘y’ or both
direction. In case of single directional shearing (e.g. in ‘x’
direction can be viewed as an object made up of very thin layer
and slid over each other with the base remaining where it is).
Shearing is a non-rigid-body transformation that moves objects

Mohan Bhandari (CG)


with deformation.

20
5. Shearing

Mohan Bhandari (CG)


21
5. Shearing

Mohan Bhandari (CG)


22
Homogenous Coordinates
The matrix representations for translation, scaling and rotation
are respectively:
• Translation: P’ = T + P (Addition)
• Scaling: P’ = S . P (Multiplication)
• Rotation: P’ = R . P (Multiplication)

Mohan Bhandari (CG)


Since, the composite transformation such as include many
sequence of translation, rotation etc and hence the many naturally
differ addition & multiplication sequence have to perform by the
graphics allocation. Hence, the applications will take more time for
rendering.
Thus, we need to treat all three transformations in a consistent
way so they can be combined easily & compute with one
mathematical operation. If points are expressed in homogenous
coordinates, all geometrical transformation equations can be
represented as matrix multiplications. 23
Homogenous Coordinates

Mohan Bhandari (CG)


24
Homogenous Coordinates
Here, in case of homogenous coordinates we add a third
coordinate ‘h’ to a point (x, y) so that each point is represented
by (hx, hy, h). The ‘h’ is normally set to 1. If the value of ‘h’ is
more the one value then all the co-ordinate values are scaled by
this value.

Mohan Bhandari (CG)


25
Homogenous Coordinates
• For translation

With T( tx , ty ) as translation matrix, inverse of this translation matrix is

Mohan Bhandari (CG)


obtained by representing tx, ty with -tx, -

• For rotation

Here, figure-a shows the Counter Clockwise (CCW) rotation & figure-b
shows the Clockwise (CW) rotation.
26
• For scaling

• For Reflection
• Reflection about x-axis

• Reflection about y-axis

• Reflection about y=x-axis

Mohan Bhandari (CG)


• Reflection about y=-x-axis

• Reflection about any line y=mx+c

27
Composite Transformation
With the matrix representation of transformation
equations it is possible to setup a matrix for any sequence of
transformations as a composite transformation matrix by
calculating the matrix product of individual transformation.
Forming products of transformation matrices is often referred to

Mohan Bhandari (CG)


as a concatenation, or composition, of matrices. For column
matrix representation of coordinate positions we form
composite transformation by multiplying matrices in order from
right to left.
Right to Left
A.B != B.A 28
Fixed Point Rotation

Mohan Bhandari (CG)


(Xf,Yf)
(Xf,Yf)

29
Fixed Point Rotation
Step 1: The fixed point along with the object is translated to
coordinate origin.

Mohan Bhandari (CG)


(Xf,Yf)

30
(Xf,Yf)
Fixed Point Rotation
Step 2: Rotate the objet about origin

Mohan Bhandari (CG)


(Xf,Yf)

(Xf,Yf) 31
Fixed Point Rotation
Step 3: The fixed point along with the object is translated back
to its original position.

Mohan Bhandari (CG)


(Xf,Yf) (Xf,Yf)

32
Fixed Point Rotation
Original
Image

(Xf,Yf)

Mohan Bhandari (CG)


Step 1 Step 2 Step 3
T’x = Translate its
original place

Tx = Translate to origin R θ = Rotate angle θ


(Xf,Yf)
33

(Xf,Yf) (Xf,Yf)
Fixed Point Rotation
Composite Transformation

= T’(Xf ,Yf) . R θ . T(-Xf ,-Yf)

Mohan Bhandari (CG)


= [ ][ ][ ]
1

0
0

0
Xf

Yf

1
.
Cos θ -Sin θ

Sin θ Cos θ

0 0 1
0
0
.
1

0
0

0
-Xf

-Yf

34
Exercise 1
Q. N. > Rotate the triangle (5, 5), (7, 3), (3, 3) in counter
clockwise (CCW) by 90 degree.
A:
P’ = R. P

Mohan Bhandari (CG)


=

=
.

[ ]
-5 -3 -3 35
= 5 7 3

1 1 1
Exercise 2
Q.>Rotate the triangle (5, 5), (7, 3), (3, 3) about fixed point (5, 4)
in counter clockwise (CCW) by 90 degree.
A : Solution
Here, the required steps are:

Mohan Bhandari (CG)


1. Translate the fixed point to origin.
2. Rotate about the origin by specified angle θ .
3. Reverse the translation as performed earlier.

36
Thus, the composite matrix is given by
Com = T(xf, yf) . Rθ .T(-xf, -yf)

Mohan Bhandari (CG)


37
Now, the required co-ordinate can be
calculated as:

P’ = Com . P

Mohan Bhandari (CG)


Hence, the new required coordinate points are 38
(4, 4), (6, 6) & (6, 2).
Fixed Point Scaling

Mohan Bhandari (CG)


(Xf,Yf)
(Xf,Yf)

39
Fixed Point Scaling
Step 1: The fixed point along with the object is translated to
coordinate origin.

Mohan Bhandari (CG)


(Xf,Yf)

40
(Xf,Yf)
Fixed Point Scaling
Step 2 : Scaling the objet about origin

Mohan Bhandari (CG)


(Xf,Yf)

(Xf,Yf) 41
Fixed Point Scaling
Step 3: The fixed point along with the object is translated back
to its original position.

Mohan Bhandari (CG)


(Xf,Yf) (Xf,Yf)

42
Fixed Point Scaling
Original
Image

(Xf,Yf)

Mohan Bhandari (CG)


Step 1 Step 2 Step 3
T’x = Translate its
original place
S = Scalig at origin
Tx = Translate to origin

(Xf,Yf)
43

(Xf,Yf) (Xf,Yf)
Fixed Point Rotation
Composite Transformation

= T’(Xf ,Yf) . Saxix . T(-Xf ,-Yf)

Mohan Bhandari (CG)


= [ ][ ][ ]
1

0
0

0
Xf

Yf

1
.
Sx

0
0

Sy

0 1
0
0
.
1

0
0

0
-Xf

-Yf

44
Exercise 2
Q.N.1. > Find the coordinate of a triangle A(1,3) , B(2,5) and C(3,3)
after twice its original size
a) about origin
b)about fixed point (2,3)
Q.N.2. > Find the coordinate of a triangle A(1,3) , B(2,5) and C(3,3)

Mohan Bhandari (CG)


after being rotated about fixed point p(2,4) by 45 in clockwise
direction and then translate (3,4) .

Q.N.3.>Find the coordinate of a triangle A(1,3) , B(2,5) and C(3,3) after


being rotated about fixed point p(2,4) by 45 in clockwise direction and
then translate by 3 unit along x-direction.

Q.N.4 >Find the coordinate of a triangle (5, 5), (7, 3), (3, 3) after scaling
(2,3) and then rotate 45 CCW then translate (1,1) and then reflect y=0 45
line.
[Link] the coordinate of a triangle (5, 5), (7, 3), (3, 3) after
translate (1,0) then scaling (3,3) then rotate 45 CW then
translate (1,1) and then reflect x=0 line.
[Link] the coordinate of a line (5, 5), (3, 3) after rotate 450
ccw at fixed point (3,3) then translate (1,1) then reflect at
x-axis.
[Link] the coordinate of a point (5, 5) after reflection y-axis

Mohan Bhandari (CG)


then scaling twice then rotate 30 CW then rotate 300 CW
at fixed point (3,4)
4. Draw a circle at (3,4) with radius 10.
[Link] an ellipse where x-radius is 6 and y-radius is 8 at
center (0,0)
[Link] the line (1,10) and (10,9) using BLA.
[Link] the line A(1,5) and B(20,55) where windows has 46
P1(5,5) and P2(50,50).
Reflection about Line y=mx+c

Mohan Bhandari (CG)


47
Reflection about Line y=mx+c

Mohan Bhandari (CG)


48
Reflection about Line y=mx+c

Mohan Bhandari (CG)


49
Reflection about Line y=mx+c

Mohan Bhandari (CG)


50
Reflection about Line y=mx+c

CM=T’(0,C) . R’θ. Rrefl. Rθ . T(0,-C)

Mohan Bhandari (CG)


51
Exercise
Q.N.1 > Reflect an object (2, 3), (4, 3), (4, 5) about line y = x +1.
Solution
Here,
The given line is y = x +1.

Mohan Bhandari (CG)


Thus,
When x = 0, y=1
When x = 1, y=2
When x = 2, y=3

Also,
The slope of the line (m) = 1 52
Thus, the rotation angle (θ) = Tan-1(m) = Tan-1(1) = 450
Here, the required steps are:
• Translate the line to origin by decreasing the y-intercept with
one.
• Rotate the line by angle 450 in clockwise direction so that the
given line must overlap x-axis.
• Reflect the object about the x-axis.
• Reverse rotate the line by angle -450 in counter-clockwise
direction.

Mohan Bhandari (CG)


• Reverse translate the line to original position by adding the y-
intercept with one.

Thus, the composite matrix is given by:


CM=T’(0,C) . R’θ. Rrefl. Rθ . T(0,-C)

53
Mohan Bhandari (CG)
54
Mohan Bhandari (CG)
55
Now, the required co-ordinate can be calculated as:
P’ = Com x P

Mohan Bhandari (CG)


56
Hence, the final coordinates are (2, 3), (2, 5) & (4, 5).
Exercise
Q.N.> Reflect a triangle A(1,8) B(3,8) and C(1,6)
about line y= x+2

Mohan Bhandari (CG)


X Y
0 2
1 3
2 4
3 5

57
Exercise (Imp)
Q.N> A mirror is placed such that it passes through (0,10),
(10, 0). Fin the mirror image of an object (6,7), (7, 6), (6, 9).

Solution

Mohan Bhandari (CG)


Here,
The given mirror or line is
passing through the
points (0, 10) & (10, 0).
Now, the slope of the line
(m) = (y2-y1) / (x2-x1)
= (0 - 10) / (10 - 0) = -1
Thus, the rotation angle (θ) 58
= Tan -1 (m) = Tan -1(-1)
= - 450
The composite matrix is given by:
Com
= T(0, 10) or (10, 0). Rθ in CW .Rfx .R θ in CCW .T(0, -10) or (-10, 0)

Mohan Bhandari (CG)


59
Mohan Bhandari (CG)
60
Now, the required co-ordinate can be calculated as:
P’ = Com . P

Mohan Bhandari (CG)


Hence, the final coordinates are (3, 4), (4, 3) & (1, 4).

61
Home Work
• What do you mean by homogeneous coordinates? Rotate a
triangle A(5,6), B(6,2) and C(4,1) by 45 degree about an
arbitrary pivot point (3,3). (2072 TU).
• Use Bresenham's algorithm to draw a line having end points
(25, 20) and (15, 10). (2072 TU).

Mohan Bhandari (CG)


• Given a clipping window P(0,0), Q(30,20), S(0,20) use the
Cohen Sutherland algorithm to determine the visible portion
of the line A(10,30) and B(40,0). (2072 TU)

62
Two Dimensional Viewing
• Two-dimensional viewing is the mechanism for displaying
views of a picture on an output device. Much like what we see
in real life through a small window on the wall or the

Mohan Bhandari (CG)


viewfinder of a camera, a computer-generated image often
depicts a partial view of a large scene. For a 2-D picture, a
view is selected by specifying a subarea of the total picture
area.

63
2D Coordinate System
1. Modeling Coordinates
• Modeling coordinates are used to construct shape of individual parts
(objects or structures) of a 2D scene. For example, generating a circle
at the origin with a “radius” of 2 units.
• Here, origin (0, 0), and radius 2 units are modeling coordinates.

Mohan Bhandari (CG)


• Modeling coordinates define object shape.
• Can be floating-point, integers and can represent units like km, m,
miles, feet etc.

View Coordinates Device Coordinates


64
2D Coordinate System..
2. World Coordinates
• World coordinates are used to organize the individual parts
into a scene.
• World coordinates units define overall scene to be modeled.

Mohan Bhandari (CG)


• World coordinates represent relative positions of objects.
• Can be floating-point, integers and can represent units like km,
m, miles etc.

65
2D Coordinate System..
3. Viewing Coordinates
• Viewing coordinates are used to define particular view of the user.
Viewer‟s position and view angle i.e. rotated/translated.
• Viewing coordinates specify the portion of the output device that is
to be used to present the view.

Mohan Bhandari (CG)


• Normalized viewing coordinates are viewing coordinates between 0
and 1 in each direction. They are used to make the viewing process
independent of the output device (paper, mobile).

66
View Coordinates
2D Coordinate System..
4. Device Coordinates or Screen Coordinates
• The display coordinate system is called device coordinate
system. Device coordinates are specific to output device.
• Device coordinates are integers within the range (0, 0) to

Mohan Bhandari (CG)


(xmax, ymax) for a particular output device.

67
Device Coordinates
2D Coordinate System..

Mohan Bhandari (CG)


View Coordinates Device Coordinates

68
Window and Viewport
Window:
• A world-coordinate area selected for display is called a window or clipping
window. That is, window is the section of the 2D scene that is selected for
viewing.
• The window defines what is to be viewed.
Viewport
• An area on a display device to which a window is mapped is called a viewport.

Mohan Bhandari (CG)


• The viewport indicates where on an output device selected part will be
displayed.

69
Window to Viewport transformation
A window is specified by four world coordinates: Xwmin, Xwmax, Ywmin
and Ywmax (see Fig.). Similarly, a viewport is described by four normalized
device coordinates: Xvmin, Xvmax, Yvmin and Yvmax.

Window Viewport

Mohan Bhandari (CG)


1. Translate the window to the origin. That is, apply T (-Xwmin, -Ywmin)
2. Scale it to the size of the viewport. That is, apply S (sx, sy)
3. Translate scaled window to the position of the viewport. That is, apply
T(Xvmin, Yvmin). 70
Therefore, net transformation,
TWV = T (Xvmin, Yvmin). S(sx, sy).T(-Xwmin, -Ywmin)
• Let (x, y) be the world coordinate point that is mapped onto the
viewport point (u, v), then we must have

=
=

Mohan Bhandari (CG)


=
=
Where
71
Window to Viewport transformation

Mohan Bhandari (CG)


72
Window to Viewport transformation

Mohan Bhandari (CG)


73
Window and Viewport……
• Window and viewport are often rectangular in standard
positions, because it simplifies the transformation process and
clipping process. Other shapes such as polygons, circles take
longer time to process. By changing the position of the
viewport, we can view objects at different positions on the

Mohan Bhandari (CG)


display area of an output device. Also by varying the size of
viewports, we can change size of displayed objects. Zooming
effects can be obtained by successively mapping different-sized
windows on a fixed-sized viewport.

74
Two-Dimensional Viewing Pipeline

Mohan Bhandari (CG)


• The mapping of a part of a world co-ordinate scene to a device co-
ordinate is referred to as viewing transformation.
• Sometimes, the 2D viewing transformation is simply referred to as
the window–to–viewport transformation or the windowing
transformation.
• The transformation that maps the window into the viewport is
applied to all of the output primitives (lines, rectangles, circles) in
world coordinates. 75
• This viewing transformation involves several steps.
Clipping
• The process of identifying those portions of a picture that are
either inside or outside of the specified region of space is
called clipping.
Two possible ways to apply clipping in the viewing transformation:
1. Apply clipping in the world coordinate system: ignore objects that

Mohan Bhandari (CG)


lie outside of the window.
2. Apply clipping in the device coordinate system: ignore objects that
lie outside of the viewport.

Before Clipping After Clipping

76
Clipping..
Why Clipping?
1. Excludes unwanted graphics from the screen.
2. Improves efficiency, as the computation dedicated to
objects that appear off screen can be significantly reduced.

Mohan Bhandari (CG)


Applications:
1. In drawing and painting, it is used to select picture parts for
copying, erasing, moving.
2. Displaying a multi-window environment.

77
Point Clipping
• Let W denote a clip window with coordinates (xwmin, ywmin),
(Xwmin, Ywmax), (Xwmax, Ywmin), (Xwmax, Ywmax), then a
vertex (x, y) is displayed only if following “point clipping”
inequalities are satisfied:
Xwmin ≤ x ≤ Xwmax,

Mohan Bhandari (CG)


Ywmin ≤ y ≤ Ywmax.
• Very simple and efficient.
• Only works for vertices.

78
Line Clipping
• Lines that do not intersect the clipping window are either
completely inside the window or completely outside the
window. On the other hand, a line that intersects the clipping
window is divided by the intersection point(s) into segments
that are either inside or outside the window.

Mohan Bhandari (CG)


79
For any particular line segment:
a. Both endpoints are inside the region (line AB).
• No clipping necessary.
b. One endpoint is inside and one is outside of the clipping window
(line CD).
• Clip at intersection point.
c. Both endpoints are outside the region:
• No intersection (lines EF, GH)
• Discard the line segment.

Mohan Bhandari (CG)


• Line intersects the region (line IJ)
• Clip line at both intersection points.
Before clipping After Clipping

80
Line Clipping…

Mohan Bhandari (CG)


81
Cohen-Sutherland Line Clipping Algorithm

• One of the oldest and most popular line-clipping algorithms.


In this method, coordinate system is divided into nine regions.
All regions have their associated region codes. Every line
endpoint is assigned a four digit binary code (region code or
out code). Each bit in the code is set to either a 1(true) or a

Mohan Bhandari (CG)


0(false). Assign a bit pattern to each region as shown:

Ywmax

Ywmin 82

Xwmin Xwmax
Step 1 : Establish Region code for all line end point
• First bit is 1, if x < Xwmin (Point lies to left of window) , else set it to 0
• Second bit is 1, if x > Xwmax (Point lies to right of window) , else set it to 0
• Third bit is 1, if y < Ywmin (Point lies to below window), else set it to 0
• Fourth bit is 1, if y > Ywmax (Point lies to above window) , else set it to 0

Fourth Bit

Mohan Bhandari (CG)


Ywmax

First Bit Second Bit


Ywmin
83

Third Bit
Xwmin Xwmax
Step 2: Determine which lines are completely inside window
and which are not
a) If both end points of line has region codes ‘0000’ line is
completely inside window.
b) If logical AND operation of region codes of two end points is
NOT ‘0000’. The line is completely outside (some bit position
have 1’s)

Mohan Bhandari (CG)


Astart 0000
Aend 0000 C
Completely inside

C 1001
D 0001 D
AND
0001
Completely Outside 84
Step 3 : If both tests fail then line is partially visible so we need to
find the intersection with boundaries of window .

a) If 1st bit is 1 then line intersect with Left boundary and

• Yi= Y1 + m (X – X1) where X= Xwmin


b) If 2nd bit is 1 then line intersect with Right boundary and

• Yi= Y1 + m (X – X1)

Mohan Bhandari (CG)


where X= Xwmax
c) If 3rd bit is 1 then line intersect with Bottom boundary and

• Xi= X1 + (1/m) (Y – Y1) where Y= Ywmin


d) If 4th bit is 1 then line intersect with Top boundary and

• Xi= X1 + (1/m) (Y – Y1) where Y= Ywmax


85
Here, (Xi , Yi) are (X ,Y) intercepts for that the step 4 repeat step 1 through step 3
until line is completely accepted or rejected
Cohen-Sutherland Line Clip Examples

Mohan Bhandari (CG)


86
Cohen-Sutherland Line Clip Examples

Mohan Bhandari (CG)


87
Numerical
Q. Clip a line with end point A(5,30) , B(20,60) against a clip window with
lower most left corner at P1(10,10) and upper right corner at P2(100,100)
Ans:
P2(100,100)
Step 1: Establish the region
codes for end point A,B
A(5,30) B(20,60)
5<10 : (true)= 1 20<10: (false) =0
5>100 : (false) =0 20>100: (false)=0
30<10 : (false) =0 60<10 : (false)=0

Mohan Bhandari (CG)


30>100 : (false) =0 60>100: (false)=0 P1(10,10)
A(5,30) = 0001 B(20,60)=0000

Step 2: Visibility check


A: 0001
B: 0000 Partial Visibility After Clipping P2(100,100)
AND
0000
Step 3: Intersection point with boundary
A: 0001 , Condn of 1st bit is 1
Yi= Y1 + m (X – X1) where , X= 10 88
= 30 + 2 (10-5)
= 40
P1(10,10)
(X,Y)=(10,40)
Q. Clip a line with end point A(5,15) , B(110,60) against a clip
window with lower most left corner at P1(10,10) and upper
right corner at P2(100,100)

Q. Given a clipping window P (30,0), S(0,20) use the Cohen


Sutherland algorithm to determine the visible portion of the
line A(10,30) and B(40,0).

Mohan Bhandari (CG)


Q. . Given a clipping window P(0,0), Q(10,20), S(0,20) use the
Cohen Sutherland algorithm to determine the visible portion of
the line A(10,30) and B(40,0).

Q. Clip a line with end point A(1,60) , B(20,120) against a clip


window with lower most left corner at P1(10,10) and upper 89
right corner at P2(100,100)
Polygon Clipping
• A polygon can be defined as a geometric object "consisting of
a number of points (called vertices) and an equal number of
line segments (called sides or edges). Polygon clipping is
defined as the process of removing those parts of a polygon
that lie outside a clipping window. Consider a general polygon

Mohan Bhandari (CG)


that is clipped with respect to a rectangular viewing region.

Window Window

90
Before clipping After clipping
Sutherland-Hodgeman Polygon Clipping Algorithm
• The Sutherland-Hodgeman Polygon-Clipping Algorithms clips a
given polygon successively against the edges of the given clip-
rectangle. It starts with the initial set of polygon vertices, first
clips the polygon against the left rectangle boundary of the
window. Then successively against the right boundary, bottom
boundary, and finally against the top boundary, as shown in

Mohan Bhandari (CG)


figure.

Original Polygon Clip Left Clip Right Clip Bottom Clip Top
91
Chapter 3

Mohan Bhandari (CG)


Finished
92

You might also like