Steps uses in the Cohen Sutherland Line Clipping Algorithm are:
Figure: Steps for Cohen Sutherland Line Clipping
STEP 1:
Input:
x_{L} , x_{R} , y_{T} , y_{B} , P_{1} ( x_{1} , y_{1} ), P_{2} ( x_{2} , y_{2} )
Initialize i = 1
While i <= 2
if x_{i} < x_{L} then bit 1 of code -P_{i} = 1 else 0
if x_{i} > x_{R} then bit 2 of code -P_{i} =1 else 0
: The endpoint codes of the line are then set
if y_{i} < y_{B} then bit 3 of code -P_{i} = 1 else 0
if y_{i} > y_{T} then bit 4 of code -P_{i} = 1 else 0
i = i +1
end while
i = 1
STEP 2:
Initialize j = 1
While j <= 2
if x_{j} < x_{L} then C_{j} left = 1 else C_{j} left = 0
if x j > x R then C j right = 1 else C j right = 0
: Set flags as per to the position of the line endpoints with respect to window
if y_{j} < y_{B} then C_{j} bottom = 1 else C_{j} bottom = 0 edges
if y _{j} > y_{T} then C_{j} top = 1 else C _{jtop} = 0
end while
STEP 3: If codes of P1and P2 are both equivalent to zero then draw P_{1}P_{2} are wholly visible
STEP 4: If logical intersection or AND operation of code -P_{1} and code -P_{2} is not equivalent to zero then avoid P_{1}P_{2} are wholly invisible
STEP 5: If code -P_{1}= 0 then swap P_{1} and P_{2} with their flags and also set i = 1
STEP 6: If code -P_{1} < > 0 then
for i = 1,
{if C_{1 left} = 1 then
find intersection ( x_{L }, y'_{L} )
assign code to ( x_{L} , y'_{L} )
P1 = ( x_{L} , y'_{L} )
end if
i = i + 1;
go to 3
}
with left edge vide eqn. (C)
for i = 2,
{if C_{1 right} = 1 then
find intersection ( x_{R} , y'_{R} ) with right edge vide eqn. (D)
assign code to ( x_{R} , y'_{R} )
P_{1} = ( x_{R} , y'_{R} )
end if
i = i + 1 go to 3
}
for i = 3
{if C1 bottom = 1 then
find intersection ( x '_{B} , y_{B} ) with bottom edge vide eqn. (B)
assign code to ( x '_{B} , y_{B} )
P1 = ( x '_{B} , y_{B} )
end if
i = i + 1 go to 3
}
for i = 4,
{if C_{1 top} = 1 then
find intersection ( x '_{T} , y_{T} ) vide eqn. (A) with top edge assign code to ( x '_{T} , y_{T} )
P_{1} = ( x '_{T} , y_{T} )
end if
i = i + 1 go to 3
}
end