KEMBAR78
Chapter-Iv Windowing - Clipping | PDF | Visual Cortex | Geometry
0% found this document useful (0 votes)
29 views73 pages

Chapter-Iv Windowing - Clipping

all basic gave of 4th unit
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)
29 views73 pages

Chapter-Iv Windowing - Clipping

all basic gave of 4th unit
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/ 73

COMPUTER GRAPHICS

CGR-22318
UNIT-IV
WINDOWING AND CLIPPING

Ms. S.A.Salunkhe
03-11-2020
POINTS TO BE COVERED
• INTRODUCTION

• WINDOWING AND CLIPPING CONCEPT

• WINDOW TO VIEWPORT TRANSFORMATION

• LINE CLIPPING

• COHEN-SUTHERLAND LINE CLIPPING ALGORITHM

• COHEN-SUTHERLAND SUBDIVISION LINE CLIPPING ALGORITHM

• CYRUSBECK ALGORITHM

• LIAN BARSKY ALGORITHM

• MIDPOINT SUBDIVISION ALGORITHM

• POLYGON CLIPPING
03-11-2020
INTRODUCTION
• Formal mechanism for displaying of a picture on an output
device.

• It allows a user to specify which part of a defined picture is to


be displayed & where that part is to be placed on the display
device.

• To define a picture, world-coordinate reference frame is used.

• From a picture, user can select a specific area.

• This selected area can be displayed on the display device.


03-11-2020
WINDOWING AND CLIPPING CONCEPT
• WINDOWING
• The process of selecting and viewing the picture with
different views is called windowing.

• CLIPPING
• The process which divides each element of the picture into its
visible and invisible portions, allowing the invisible portion
to be discarded is called as clipping.

03-11-2020
Picture
Picture element
element
outside
inside
window.
window
Needs to be clipped

Clipped picture
element inside
window
03-11-2020
WINDOW TO VIEWPORT
• TRANSFORMATION
The picture element is stored in computer memory using any
convenient Cartesian co-ordinate system referred to as WORLD
COORDINATE SYSTEMS (WCS).

• When picture is displayed on the display device it is measured in


Physical Device Coordinate System (PDCS) corresponding to the
display device.

• The mapping of the coordinates of the points and lines that form
the picture into the appropriate physical device coordinate is called
as viewing transformation.
03-11-2020
WINDOW TO VIEWPORT
• TRANSFORMATION
THE VIEWING TRANSFORMATION PIPELINE

• A world coordinate system are selected for display is called a


window.

• An area on a PDCS to which a window is mapped is called a


viewport.

• The window defines what is to be viewed.

• The viewport defines where it is to be displayed.

03-11-2020
WINDOW TO VIEWPORT
TRANSFORMATION
The mapping of a part of a WCS to PDCS is
referred to as a
viewing transformation.
Viewport
Window YWmax
YWmax

YWmin YWmin

XWmin XWmin XWmax


XWmax World
Device Coordinates
Coordinates

03-11-2020
WINDOW TO VIEWPORT
• TRANSFORMATION
The 2-dimensional viewing transformation pipeline

NVC using
Construct WC
Convert WC to window Convert NVC
Scene Using MC
VC viewport to DC
transformation
specification

MC WC VC NVC DC

• MC-MODELING COORDINATES
• WC – WORLD COORDINATES
• VC – VIEWING COORDINATES
• NVC – NORMALIZED VIEWING
COORDINATES
03-11-2020
• DC – DEVICE COORDINATES
WINDOW TO VIEWPORT
• TRANSFORMATION
The position of the viewport can also be changed.

• Objects canbe viewedat different position on the


display area of an output device.

• The size of the viewport can also be changed.

Y world
Window 1

Viewport
Y0

X world 0
03-11-2020 X0 1
CLIPPING
• The correct way to select visible information for display is to use
clipping

• Clipping is a process which divides each element of the picture in


to its visible and invisible portions, allowing the invisible portion
to be discarded

• Clipping can be applied to a variety of different types of picture


elements such as pointer, lines, curves, text character and polygons

03-11-2020
CLIPPING
• LINE CLIPPING
• The lines are said to be interior to the clipping window and
hence visible if both the end points are interior to the
window.

• If both end points of a line are exterior to the window, the


line is not necessarily completely exterior to the window.

03-11-2020
CLIPPING
• If both end points of a line are

• Completely right of
• Completely left of
WINDOW
• Completely above
• Completely below

• Then the line is completely exterior to the window and hence


invisible.
03-11-2020
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM

• WORKING
• Divide view plane into 9 regions defined by viewport edges
• Assign each region a 4-bit outcode:

1 001 1000 1010


y
max

0000
0 001 WINDOW 0010

y
min

101
x x
min max
03-11-2020 0
0100
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM

• To what do we assign outcodes?


• How do we set the bits in the outcode?
• How do to use them?

1 001 1000 1010


y
max

0 001 0000 0010

y
min

101
x x
min max
03-11-2020 0
0100
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
• Set bits with simple tests
x > xmax y < ymin etc.

• Assign an outcode to each vertex of line


– If both outcodes = 0, trivial accept

– bitwise AND vertex outcodes together


– If result ≠ 0, trivial reject 1001 1000 1010
y
max

• As those lines lie on one side of the


0001 0000 0010
boundary lines
y x
min x
03-11-2020 0101 min 0100 0110
max
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM

• If line cannot be trivially accepted or rejected, subdivide so


that one or both segments can be discarded

• Pick an edge that the line crosses (how?)

• Intersect line with edge (how?)

• Discard portion on wrong side of edge and assign outcode to


new vertex

• Apply trivial accept/reject tests; repeat if necessary


03-11-2020
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
• If line cannot be trivially accepted or rejected, subdivide so that one or
both segments can be discarded

• Pick an edge that the line crosses


– Check against edges in same order each time
• For example: top, bottom, right, left
E
D
C

03-11-2020
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
• Intersect line with edge (how?)
E
D
C

D
C

03-11-2020
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
• EXAMPLE
• Consider the clipping window and the lines shown in figure. Find the
region code for each end point and identify the line is completely visible,
partially visible or completely visible.

03-11-2020
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
• SOLUTION

1000

1001 P9 1010

y
max P4 P2

P1 P10
0001 0000
P8
P6
P3 0010
P5
y
min x x
min max
0101 0100 P7 0110

03-11-2020
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
LOGICAL
LINE END POINT CODES RESULT
ANDing

P1P2 0000 0000 0000 Completely Visible

Completely
P3P4 0001 0001 0001
Invisible

P5P6 0001 0000 0000 Partially Visible

P7P8 0100 0010 0000 Partially Visible

PP 1000 0010 0000 Partially Visible


9 10

03-11-2020
COHEN-SUTHERLAND SUBDIVISION LINE
CLIPPING ALGORITHM
• WORKING
• The Cohen Sutherland algorithm begins the clipping process for a partially
visible line by comparing an outside endpoint to a clipping boundary to
determine how much of the line can be discarded.

• Then the remaining part of the line is checked against the other
boundaries, and the process is continued until either the line is totally
discarded or a section is found inside the window.

03-11-2020
03-11-2020
COHEN-SUTHERLAND SUBDIVISION LINE
CLIPPING ALGORITHM
• The intersection points with a clipping boundary can be calculated using
the slope-intercept form of the line equation.

• The equation for line Passing through Points P1 (x1, y1) and P2 (x2, y2) is

𝑦 = 𝑚 𝑥 − 𝑥1 + 𝑦1 𝑜𝑟 𝑦 = 𝑚 𝑥 − 𝑥2 + 𝑦2

𝑦 2 − 𝑦1
𝑤ℎ𝑒𝑟𝑒, 𝑚= 𝑥 −𝑥 (slope of the line)
2 1

03-11-2020
COHEN-SUTHERLAND SUBDIVISION LINE
CLIPPING ALGORITHM
• Therefore, the intersections with the clipping boundaries of the window
are given as:

• Left: 𝑥𝐿, 𝑦 = 𝑚 𝑥𝐿 − 𝑥1 + 𝑦1; 𝑚≠∞

• Right: 𝑥 𝑅, 𝑦 = 𝑚 𝑋𝑅 − 𝑥1 + 𝑦1; 𝑚≠∞

1
• Top: 𝑦 𝑇, 𝑥 = 𝑥 1 + 𝑦𝑇 − 𝑦1; 𝑚≠0
𝑚

1
• Bottom: 𝑦𝐵, 𝑥 = 𝑥1 + 𝑦 𝐵 − 𝑦1 ; 𝑚≠0
𝑚

03-11-2020
ALGORITHMS STEPS
1. Read two end Points of the line say P1 (x1, y1) and P2 (x2, y2).
2. Read two corners (left-top and right-bottom) of the window, say (Wx1, Wy1 and Wx2, Wy2).
3. Assign the region codes for two end points P1 and P2 using following steps :
• Initialize code with bits 0000
– Set Bit 1 - If (x < Wx1)
– Set Bit 2 - If (x > Wx2)
– Set Bit 3 - If (y < Wy2)
– Set Bit 4 - If (y > Wy1)
4. Check for visibility of line P1 P2
– a) If region codes for both endpoints P1 and P2 are zero then the line is completely visible. Hence draw the line
and go to step 9.
– b) If region codes for endpoints are not zero and the logical ANDing of them is also nonzero then the line is
completely invisible, so reject the line and go to step 9.
– c) If region codes for two endpoints do not satisfy the conditions in 4a. and 4b. the line is partially visible.
5. Determine the intersecting edge of the clipping window by inspecting the region codes of two
endpoints.
– a) If region codes for both the end points are non-zero, find intersection points P’1 and P’2 with boundary edges
of clipping window with respect to point P1 and point P2,respectively
– b) If region code for any one end Point is non-zero then find intersection Point P’1 or P’2 with the boundary edge
of the clipping window with respect to it.
6. Divide the line segments considering intersection points.
7. Reject the Line segment if any one end Point of it appears outsides the clipping window.
8. Draw the remaining line segments.
9. Stop.
03-11-2020
COHEN-SUTHERLAND SUBDIVISION LINE CLIPPING
ALGORITHM
• EXAMPLE - 1
• Clip two lines P1 (40,15) - P2 (75,45) and P3 (70,20) – P4 (100,10) against a
window A (50,10) , B (80,10) , C (80,40) & D (50,40).

x 1000 x
min max
P2
1001 1010

y
max

0001 P1 0000 0010

y
min
0101 0100 0110
COHEN-SUTHERLAND SUBDIVISION LINE CLIPPING
ALGORITHM
• SOLUTION
• Line 1 : P1 (40,15) - P2 (75,45)

• 𝑥𝐿 = 50, 𝑦𝐵 = 10, 𝑋𝑅 = 80, 𝑦𝑇 = 40

POINT END CODE ANDing RESULT


P1 0001 PARTIALLY
0000
P2 0000 VISIBLE

𝑥𝐿, 𝑦 = 𝑚 𝑥𝐿 − 𝑥1+ 𝑦1

𝑦 2 − 𝑦1 6
= 50 − 40 + 15 = 𝟐𝟑. 𝟓𝟕 I1 =
𝑚= 𝑥 −𝑥 7
2 1
50,23.57
45 − 15 𝟔
= = 𝑦𝑇, 𝑥 = 𝑥1 + 1/𝑚 + (𝑦𝑇 − 𝑦1)
75 − 40 𝟕 I2 = (690.6,40)
= 40 + 1.16 + (40 − 15) = 𝟔𝟗. 𝟏𝟔
COHEN-SUTHERLAND SUBDIVISION LINE CLIPPING
ALGORITHM
• EXAMPLE - 2
• Clip two lines P1 (40,15) - P2 (75,45) and P3 (70,20) – P4 (100,10) against a
window A (50,10) , B (80,10) , C (80,40) & D (50,40).

x 1000 x
min max

1001 1010

y
max

P3
0001 0000 0010

y
min
0101 0100 0110
P4
COHEN-SUTHERLAND SUBDIVISION LINE CLIPPING
ALGORITHM
• SOLUTION
• Line 2 : P3 (70,20) – P4 (100,10)

• 𝑥𝑅 = 50, 𝑦𝐵 = 10, 𝑋𝑅 = 80, 𝑦𝑇 = 40

POINT END CODE ANDing RESULT


P1 0000 PARTIALLY
0000
P2 0010 VISIBLE

𝑦 − 𝑦1 𝑥𝑅, 𝑦 = 𝑚 𝑥𝑅 − 𝑥1 + 𝑦1
𝑚= 2
𝑥2 − 𝑥1 −1
= 80 − 70 + 20 I = 80,16.66
10 − 20 −𝟏 3
= =
100 − 70 𝟑 = 𝟏𝟔. 𝟔𝟔
COHEN-SUTHERLAND SUBDIVISION LINE CLIPPING
ALGORITHM

• Clip a line P1 (-13,5) - P2 (17,11) against a window having its lower left
corner at (-8,-4) & upper right corner at (12,8).

x 1000 x
max
min
1010
1001
P2
y
max

P1
0000 0010
0001

y
min
0101 0100 0110
COHEN-SUTHERLAND SUBDIVISION LINE CLIPPING
ALGORITHM
• SOLUTION
• Line 1 : P1 (-13,5) - P2 (17,11)

• 𝑥𝐿 = −8, 𝑦𝐵 = −4, 𝑋𝑅 = 12, 𝑦𝑇 = 8

POINT END CODE ANDing RESULT


P1 0001 PARTIALLY
0000
P2 1010 VISIBLE

𝑥𝐿, 𝑦 = 𝑚 𝑥𝐿 − 𝑥1 + 𝑦1

𝑦 2 − 𝑦1 1
= −8 − (−13) + 5 = 𝟔 I1 = −8,
𝑚= 𝑥 −𝑥 5
2 1
6
11 − 5 𝟏
= = 𝑦𝑇, 𝑥 = 𝑥1 + 1/𝑚 + (𝑦𝑇 − 𝑦1)
17 + 13 𝟓 I2 = (2, 8)
= −13 + 5 + (8 − 5) = 𝟐
CYRUSBECK
ALGORITHM
• This algorithm is applicable for non rectangular
clipping
window.

• It includes an arbitrary convex region.

• The algorithm uses a parametric equation of a line segment to


find the intersection points of a line with the clipping edges.
03-11-2020
CYRUSBECK
ALGORITHM
• PARAMETRIC EQUATION OF A LINE

𝑃 𝑡 = 𝑃1 + 𝑃2 − 𝑃1 𝑡 0 < t < 1

𝑖𝑓 𝑡 = 0 → = 𝑃1
𝑃 𝑡
= 𝑃2
𝑖𝑓 𝑡 = 1 → 𝑃 𝑡

03-11-2020
CYRUSBECK
ALGORITHM• DOT PRODUCT
𝒏. [𝑷 𝒕 − 𝒇]
Y
Boundary Point
f
• 𝑖𝑓 < 0 → 𝑃 𝑡 − 𝑓 𝑖𝑠 𝑒𝑥𝑡𝑒𝑟𝑖𝑜𝑟
R
n Convex Region
• 𝑖𝑓 > 0 → 𝑃 𝑡 − 𝑓 𝑖𝑠 𝑖𝑛𝑡𝑒𝑟𝑖𝑜𝑟

X
0
• 𝑖𝑓 = 0 → 𝑃 𝑡 − 𝑓
𝑖𝑠 𝑝𝑎𝑟𝑎𝑙𝑙𝑒𝑙 𝑡𝑜 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦

03-11-2020
CYRUSBECK
ALGORITHM
Y
P2

n.[P(t)-f]>0
n.[P(t)-f]<0

n.[P(t)-f]=0
n
P1
X
0

03-11-2020
CYRUSBECK
• SubstituteALGORITHM
value of P(t) in the dot product
𝑛. [𝑃1 + P2 − P1 . t − f = 0
𝑛. 𝑃1 − 𝑓+ 𝑛. 𝑃2 − 𝑃1 . 𝑡 = 0

• Now let us say 𝑃2 − 𝑃1 is Distance Parameter (D)


and
𝑃1 − 𝑓 is Weighting Parameter (W)
𝑛. 𝑊 + 𝑛. 𝐷𝑡 = 0
𝑛. 𝐷𝑡 = −𝑛. 𝑊

−𝑛. 𝑊
𝑡=
𝑛. 𝐷
03-11-2020
CYRUSBECK
• When we get value of 𝑛. 𝐷 < 0 , then we get upper limit value
ALGORITHM
(tU)

• When we get value of 𝑛. 𝐷 > 0, then we get lower limit value


(tL)

• If the values of all set of t does not satisfies the condition


0 < t < 1 , then IGNORE those values

• Find the MAXIMUM LOWER LIMIT VALUE (tL) and MINIMUM


UPPER LIMIT VALUE (tU)

• Substitute these values in parametric equation.


03-11-2020
CYRUSBECK
• ALGORITHM
EXAMPLE-1
• The below fig. shows the Hexagonal clipping window. The line
P1(-2,1) to P2(6,3) is to be clipped to this window. Find the
Y
intersection points. V4

6
V3
5 V5
4 P2(6,3)
3
V6
2 V2
P1(-2,1) 1
V1
X
0
03-11-2020
-2 1 2 3 4 5 6
• FOR EDGE – V1,V2 • 𝑡𝐿 = −𝑛.𝑊
𝑛.𝐷
• D = P2 – P1 = [6 3]-[-2 1] = [8 2]
• = − −4
• f = (3,0) 10

4
• W = P1 – f = [-2 1]-[3 0] = [-5 1] •
10
=
• n = [1 1] • = 𝟎.
• W.n & D.n 𝟒

• W.n = [-5 1][1 1] = [-4] and

• D.n = [8 2][1 1] = [10]

• D.n > 0 = tL
Y
V4

6
V3
5 V5

4 P2(6,3)
3
V6
2 V2

P1(-2,1) 1
V1
X
0

-2 1 2 3 4 5 6
EDGE n f W n.W n.D t t
L (max) U (min)

V1 V2 [1 1] [3 0] [-5 1] -4 10 0.4 -

V2 V3 [1 0] [1 4] [-3 -3] -3 8 0.375 -

V3 V4 [1 -1] [1 4] [-3 -3] 0 6 0 -

V4 V5 [-1 -1] [5 4] [-7 -3] 10 -10 - 1

V5 V6 [-1 0] [5 4] [-7 -3] 7 -8 - 0.875

V6 V1 [-1 1] [3 0] [-5 1] 6 -6 - 1
CYRUSBECK
• ALGORITHM
The MAXIMUM LOWER LIMIT (tL) = 0.4

• The MINIMUM UPPER LIMIT (tU) = 0.875

• Substituting these values of t in parametric equation, we get,


𝑃 0.4 = −2 1 + 8 2 . 0.4 = 1.2 1.8
𝑃 0.875 = −2 1 + 8 2 . 0.875 = 5 2.75

• So the two intersection points P1 = [1.2 1.8] & P2 = [5


2.75]
with the edge V1V2 and V5V6
03-11-2020
LIANG BARSKY
• ALGORITHM
The Liang-Barsky algorithm is more efficient
Cohen
than Sutherland algorithm.

• It use the parametric equations as


& 𝑦 = 𝑦1 +
𝑥 = 𝑥1 + 𝑡∆𝑥
𝑡∆𝑦 0 ≤ 𝑡 ≤ 1 & ∆𝑦 = 𝑦2 − 𝑦1
∆𝑥 = 𝑥2 − 𝑥1

03-11-2020
LIANG BARSKY
ALGORITHM
• Liang-Barsky has 4 inequalities with two parameters p & q as
𝑡𝑝𝑖 ≤ 𝑞𝑖

• Where parameters p & q are defined as

𝑝1 = −∆𝑥, 𝑞1 = 𝑥1 − 𝑥𝑤𝑚𝑖𝑛
𝑝2 = ∆𝑥, 𝑞2 = 𝑥𝑤𝑚𝑎𝑥 − 𝑥1
𝑝3 = −∆𝑦, 𝑞3 = 𝑦1 − 𝑦𝑤𝑚𝑖𝑛
𝑝4 = ∆𝑦, 𝑞4 = 𝑥𝑤𝑚𝑎𝑥 − 𝑦1

03-11-2020
LIANG BARSKY
• ALGORITHM
Following observations canbe easily made from
above
definitions of parameters p and q

• If p1 = 0 : line is parallel to left clipping boundary.

• If p2 = 0 : line is parallel to right clipping boundary.

• If p3 = 0 : line is parallel to bottom clipping boundary.

• If p4 = 0 : line is parallel to top clipping boundary.


• If pi = 0 : lineis parallelto one of clipping
boundaries corresponding to the value of i.
• If pi < 0 : line is parallel to left clipping boundary.

• If p2 = 0 : line is parallel to right clipping boundary.

• If p3 = 0 : line is parallel to bottom clipping boundary.

• If p4 = 0 : line is parallel to top clipping boundary.

• If pi = 0 : line is parallel to one of clipping boundaries corresponding to


the value of i.

• If qi < 0 : line is completely outside the boundary and can be eliminated.

• If qi > 0 : line is inside the clipping boundary.

• If pi < 0 : line proceeds from outside to inside of the clipping boundary.

• If pi > 0 : line proceeds from inside to outside of the clipping boundary.


• The parameter t for any clipping boundary can be given as

𝑞
𝑡=
𝑝

• Liang Barsky algorithm calculates two values of parameter t:

• t1 and t2 that defines that part of the line that lies within the clip
rectangle
• t1 = determined by checking the rectangle edges for which the line
proceeds from the outside to the inside (p < 0).

• t2 = determined by checking the rectangle edges for which the line


proceeds from the inside to the outside (p > 0).
• The value of t1 is taken as largest value amongst values
of
intersections with all edges.

• The value of t2 is taken as smallest value amongst


values of intersections with all edges.

• Now, if t1 > t2, the line is completely outside the clipping window
and it can be rejected.

• Otherwise the values of t1 and t2 are substituted in the clipped


line.
• EXAMPLE – I
• Find the clipping coordinate to clip the line segment AB against the
window Liang-Barsky line clipping algorithm A (20,20), B (80,110)
and the window coordinates ae lower left corner of the window is
(40,40) and upper right corner is (100,90).

• Solution : Here,

• X1 = 20 Xwmin = 40

• Y1 = 20 Ywmin = 40

• X2 = 80 Xwmax = 100

• Y2 = 110 Ywmax = 90
• P1 = -∆x = -(x2 – x1) = - (80 -20) = -60

• P2 = ∆x = (x2 – x1) = (80 -20) = 60

• P3 = -∆y = -(y2 – y1) = - (110 -20) = -90

• P4 = ∆y = (y2 – y1) = (110 -20) = 90

• q1 = X1 – Xwmin = 20 – 40 = -20

• q2 = Xwmax – X1= 100 – 20 = 80

• q3 = Y1 – Ywmin = 20 – 40 = -20

• q4 = Xwmax – Y1= 90 – 20 = 70
• q1 / p1 = -20 / -60 = 0.33

• q2 / p2 = 80 / 60 = 1.33

• q3 / p3 = -20 / -90 = 0.22

• q4 / p4 = 70 / 90 = 0.778

• t1 = max (0.33 , 0.22) = 0.33 since for these values p < 0

• T2 = min (1.33 , 0.778) = 0.778 since for these values p > 0

• Here, t1 < t2 and the end points of clipped lines are:

• XX1 = X1 + t1 ∆x = 20 + 0.33 x 60 = 40

• YY1 = Y1 + t1 ∆y = 20 + 0.33 x 90 = 50

• XX2 = X1 + t2 ∆x = 20 + 0.778 x 60 = 66.7

• YY2 = Y1 + t2 ∆y = 20 + 0.778 x 90 = 90
MIDPOINT SUBDIVISION ALGORITHM
• The Cohen-Sutherland subdivision algorithm requires the
calculation of the intersection of the line with the window
edge.

• These calculation can be avoided by repetitively subdividing


the line at its midpoint.
MIDPOINT SUBDIVISION ALGORITHM
• The line is tested for visibility.

• if the line is completely visible it is drawn.

• If the line is completely invisible it is rejected.

• If the line is partially visible then it is subdivided in two equal


parts. The visibility test is then applied to each half.
P2 P2 P5 P2

P3 P4 P3

P1 P1 P1

(a) (b) (c)

P5 P2 P5 P5

P4 P4 P4 P3
P3 P3
P6 P6
P7
P1 P5

(d) (e) (f)

P7

(g)
POLYGON CLIPPING
• A polygon is noting but collection of lines.

• When a polygon is clipped as collection of lines, then the


original closed polygon becomes one or more open polygon
or discrete lines.
POLYGON CLIPPING
• A polygon is a closed solid model and hence after clipping it
should remain closed.

• To achieve this we require an algorithm that will generate


additional line segment which make the polygon as a closed
polygon.
LINE
a–b
c–d
d–e
f–g
h–i
Are added to polygon to make it closed
PROBLEMS WITH DISJOINT SMALLER
POLYGONS

LINE
a–b
c–d
d–e
f–g
Are included in the polygon which is not
desired.
SUTHERLAND – HODGEMAN POLYGON CLIPPING
• The Sutherland-Hodgman algorithm performs a clipping of a
polygon against each window edge in turn.

• The order to clip the polygon should be:

• 1. Clipping against the left side of the clip window.

• 2. Clipping against the top side of the clip window.

• 3. Clipping against the right side of the clip window.

• 4. Clipping against the bottom side of the clip window.


SUTHERLAND – HODGEMAN POLYGON CLIPPING

• It consists of 4 cases:
CASE-I : If the first vertex of the edge is outside the window and
second vertex is inside then the intersection point of the polygon
edge with the window boundary and the second vertex are
added to the output vertex list.

SAVE {V’1 and V2}


SUTHERLAND – HODGEMAN POLYGON CLIPPING
CASE-II : If both vertices of the edge are inside the window, then
only second vertex is added to the output vertex list.

SAVE {V2}
SUTHERLAND – HODGEMAN POLYGON CLIPPING
CASE-III : If first vertex of the edge is inside the window and
second vertex is outside then only the intersection point of the
polygon edge with the window boundary is added to the output
vertex list.

SAVE {V’1}
SUTHERLAND – HODGEMAN POLYGON CLIPPING
CASE-IV : If both vertices of the edge are outside the window,
then nothing is added to the output vertex list.

SAVE {NULL}
SUTHERLAND – HODGEMAN POLYGON CLIPPING

• EXAMPLE
• For a polygon and clipping window as shown in figure give the
list of vertices after each boundary clipping.
SUTHERLAND – HODGEMAN POLYGON CLIPPING

• SOLUTION

Left Clipped:

Output Vertex =

{V’1, V2,
V’2,V3,V’3,V4,V’4}
SUTHERLAND – HODGEMAN POLYGON CLIPPING

Top Clipped:

Output Vertex =

{V’1, V2,
V’2,V’3,V4,V’4}

Right Clipped:

Output Vertex =

{V’1, V2,
V’2,V’3,V4,V’4}
SUTHERLAND – HODGEMAN POLYGON CLIPPING

Bottom Clipped:

Output Vertex =

{V’1, V2,
V’2,V’3,V4,V’4}

Final Clipped Polygon:

{V’1, V2,
V’2,V’3,V4,V’4}

You might also like