Cohen Sutherland Line Clipping Algorithm
In the algorithm, first of all, it is detected whether line lies inside the screen or it is outside the screen.
All lines come under any one of the following categories:
- Visible
- Not Visible
- Clipping Case
1. Visible
If a line lies within the window, i.e., both endpoints of the line lies within the window. A line is visible and will be displayed as it is.
2. Not Visible
If a line lies outside the window it will be invisible and rejected. Such lines will not display. If any one of the following inequalities is satisfied, then the line is considered invisible.
Let A (x1,y2) and B (x2,y2) are endpoints of line.
xmin,xmax are coordinates of the window.
ymin,ymax are also coordinates of the window.
x1>xmax
x2>xmax
y1>ymax
y2>ymax
x1<xmin
x2<xmin
y1<ymin
y2<ymin
3. Clipping Case
If the line is neither visible case nor invisible case. It is considered to be clipped case. First of all, the category of a line is found based on nine regions given below. All nine regions are assigned codes. Each code is of 4 bits. If both endpoints of the line have end bits zero, then the line is considered to be visible.

Following figure show lines of various types

- Line AB is the visible case.
- Line OP is an invisible case.
- Line PQ is an invisible line.
- Line IJ are clipping candidates.
- Line MN are clipping candidate.
- Line CD are clipping candidate.
Advantage of Cohen Sutherland Line Clipping
- It calculates end points very quickly and rejects and accepts lines quickly.
- It can clip pictures much large than screen size.
Algorithm of Cohen Sutherland Line Clipping:
Step1:Calculate positions of both endpoints of the line.
Step2:Perform OR operation on both of these end-points.
Step3:If the OR operation gives 0000 Thenline is considered to be visible
Else
Perform AND operation on both endpoint
If And ≠ 0000
Then the line is invisible
Else
And=0000
Line is considered the clipped case.
Step4:If a line is clipped case, find an intersection with boundaries of the window m=(y2-y1 )(x2-x1)
a) If bit 1 is "1" line intersects with left boundary of rectangle window
y3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window
b) If bit 2 is "1" line intersect with right boundary y3=y1+m(X-X1)
where X = Xwmax
where X more is maximum value of X co-ordinate of the window
c) If bit 3 is "1" line intersects with bottom boundary X3=X1+(y-y1)/m
where y = ywmin
ywmin is the minimum value of Y co-ordinate of the window
d) If bit 4 is "1" line intersects with the top boundary
X3=X1+(y-y1)/m
where y = ywmax
ywmax is the maximum value of Y co-ordinate of the window.