The document discusses the Cohen-Sutherland line clipping algorithm. It describes how the algorithm performs initial tests on a line to determine if intersection calculations are needed by checking for trivial acceptance or rejection of line segments. If a line cannot be fully accepted or rejected, it is divided at a clip edge and the process is repeated iteratively until the line is fully processed. An example of applying the algorithm to clip a line against a rectangle is also provided.
2. ( x min
, y min
)
( x max
, y max
)
x = x min
x = x max
y = y min
y = y max
( x 1
, y 1
)
clip
rectangle
maxmin
maxmin
yyy
xxx
≤≤
≤≤
For a pointFor a point ((x,yx,y)) to be inside the clip rectangleto be inside the clip rectangle::
Point Clipping
3. clip
rectangle
( x a , y a )( x b , y b )
( x c , y c ) ( x d , y d )
( x 0
, y 0
)
( x 1
, y 1
)
( x , y )
clip
rectangle
( x a , y a )( x b , y b )
( x c , y c ) ( x d , y d )
( x 0
, y 0
)
( x 1
, y 1
)
( x , y )
( )
( )
1 1 1 1
1 1 1 1
1
: , 0, : ( ) ,
1
: , 0, : ( ) ,
T L
B R
Top x x y y m Left y m x x y m
m
Bottom x x y y m Right y m x x y m
m
= + − ≠ = − + ≠∞
= + − ≠ = − + ≠∞
Line Clipping
4. 0000
1000
0100
1001 1010
0001 0010
0101 0110
clip
rectangle
Region outcodesRegion outcodes
min
max
yy
yy
<
>
:1bit
:0bit
min
max
xx
xx
<
>
:3bit
:2bit
Cohen-Sutherland Algorithm
5. The Cohen-Sutherland Line-Clipping
Algorithm performs initial tests on a line to
determine whether intersection calculations
can be avoided.
1. First, end-point pairs are checked for trivial
Acceptance.
2. If the line cannot be trivially accepted, region
checks are done for Trivial Rejection.
3. If the line segment can be neither trivially
accepted or rejected, it is divided into two
segments at a clip edge, so that one segment
can be trivially rejected.
These three steps are performed iteratively until
what remains can be trivially accepted or rejected.
Cohen-Sutherland Algorithm
6. Cohen-Sutherland Algorithm
Algorithm
1-Compute the codes for the Two end points
2-Enter in loop, check if both region codes are
zero(0000 and 0000) put line in display file
for display and exit loop, return
3-If both region codes are not zero then take
logical AND of both codes, check result for
nonzero if so reject line exit loop, return
4-If result is zero then subdivide the line from
intersection point of line and clipping
boundary and repeat step 2,3,4.
5. Special Case when test 4 fails.
11. Q1. Use Cohen Sutherland Algorithm to
clip line p1(70,20) and P2 (100,10)
against window lower left hand corner
(50,10) and upper right hand corner
(80,40).
Q2. Given a clipping window A(20,20),
B(60,20), C(60,40), D(20,40). Using
sutherland cohen algorithm find the
visible portion of line segment joining
the points p(40,80),Q(120,30).