Upload
ankit-garg
View
48
Download
2
Embed Size (px)
Citation preview
Computer Graphics
Line Clipping• Cohen Sutherland Algorithm (Line)
(xmin , ymin )
(xmax , ymax )
x = xmin x = xmax
y = ymin
y = ymax
(x1, y1)
cliprectangle
maxmin
maxmin
yyyxxx
For a point For a point ((x,yx,y) ) to be inside the clip rectangleto be inside the clip rectangle::
Point Clipping
cliprectangle
(xa, ya)(xb , yb)
(xc, yc) (xd , yd)
(x0, y0)
(x1, y1)
(x , y )
cliprectangle
(xa, ya)(xb , yb)
(xc, yc) (xd , yd)
(x0, y0)
(x1, y1)
(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 mm
Bottom x x y y m Right y m x x y mm
Line Clipping
0000
1000
0100
1001 1010
0001 0010
0101 0110clip
rectangle
Region outcodesRegion outcodes
min
max
yyyy
:1bit : 0bit
min
max
xxxx
: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
Algorithm1-Compute the codes for the Two end points2-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.
cliprectangle
AB
C
D
E
An ExampleAn Example
Cohen-Sutherland Algorithm
An ExampleAn Example
cliprectangle
B
C
D
E
Cohen-Sutherland Algorithm
An ExampleAn Example
cliprectangle
B
C
D
Cohen-Sutherland Algorithm
An ExampleAn Example
cliprectangle
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).
Thank You