Computer Graphics
Line Clipping
•Cohen Sutherland Algorithm (Line)
(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 point For a point ((x,yx,y) ) to be inside the clip rectangleto be inside the clip rectangle::
Point Clipping
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
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
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
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.
clip
rectangle
A
B
C
D
E
An ExampleAn Example
Cohen-Sutherland Algorithm
An ExampleAn Example
clip
rectangle
B
C
D
E
Cohen-Sutherland Algorithm
An ExampleAn Example
clip
rectangle
B
C
D
Cohen-Sutherland Algorithm
An ExampleAn Example
clip
rectangle
B
C
Cohen-Sutherland Algorithm
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).