Page 139 - DCAP504_Computer Graphics
P. 139
Computer Graphics
The three possibilities shown in the figure 9.2 are:
(a) The line PQ lies within the window. Thus, the entire line is visible.
(b) The line JK does not cut the edge of the window and lies outside the window. Thus, the
entire line will be invisible.
(c) The line RT has one end within the window and the other end outside the window. The line
cuts the window edge at S. Thus, the portion ST will be visible and the other portion RS,
which is outside the window, will be invisible. The line LO cuts two edges of the window.
Thus, the portions LM and NO, which lie outside the window, will be invisible and the line
segment MN within the window will be visible.
From figure 9.2, it is clear that the line clipping depends on the position of the endpoints with reference
to the window edges. If the endpoints lie within the window, then the entire line is visible. If only one
endpoint lies within the window, then the line cuts the window and the visible line segment has to be
determined. If both the endpoints lie outside the window, then it has to be determined whether the line
cuts the window edges. Some algorithms are used to determine the visibility of lines. They are:
(a) Cohen Sutherland Algorithm
(b) Midpoint Subdivision Algorithm
(c) Liang-Barsky Algorithm
Evans & Sutherland (E&S) was established in 1968. The company created custom line
Did you know?
drawing routines. The Line Drawing System (LDS-1) was the first hardware
accelerated graphics system developed that introduced line clipping.
Now, let us discuss the algorithms.
9.3.1 Cohen Sutherland Algorithm
The Cohen Sutherland algorithm is the most commonly used algorithm for clipping lines against a
window frame in 2-D space. It divides the 2-D space into nine regions. Each region is assigned a 4-bit
code for identification. Cohen Sutherland algorithm does the line clipping in two phases. It first
identifies the lines that intersect the clipping window and then performs the clipping process.
As discussed in figure 9.2, you know that the lines can be in any one of the following three categories:
1. Visible: The endpoints of a line lie within the window.
2. Invisible: The endpoints of a line lie outside the window.
If a line with the endpoints (x 1, y 1) and (x 2, y 2) satisfies the below four
inequalities, then the line lies outside the window.
(x 1, x 2) > x max (y 1, y 2)> y max
(a) (x 1, x 2) < x min (y 1, y 2)< y min
3. Clipping Candidate: The line is neither in visible or invisible category. The line intersects the
clipping window.
132 LOVELY PROFESSIONAL UNIVERSITY