Page 142 - DCAP504_Computer Graphics
P. 142
Unit 9: Clipping I
or
x i = x 1 + (y i - y 1 )/m if the boundary line is horizontal
y i = y min or y max
where, m is the slope of the line. m = (y 2 - y 1)/(x 2 - x 1)
Now, the endpoint (x 1, y 1) is replaced with the intersection point (x i, y i), thereby eliminating the line
segment that lies outside the window boundary. The new endpoint is assigned a 4-bit region code and
the clipped line is re-categorized. This process is performed until the clipped line falls under either
category 1 (visible) or category 2 (invisible).
Consider the point (50, 65) is at the top and to the right of the clip window. What is the
4-bit Sutherland code (region code) of this point? You can perform the bitwise logical
OR of both top and right region code and obtain the result.
Only those lines that are partially inside and partially outside the clipping window are
checked for intersection with the window boundaries. The clipping process starts by
comparing an outside endpoint to a clipping boundary. This helps to determine which
line segments need to be discarded. This process continues till the section of the line lies
inside the clipping window.
9.3.2 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).
LOVELY PROFESSIONAL UNIVERSITY 135