Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
b4 b3 b2 b1
0 0 0 1 --- Left
0 0 1 0 --- Right
0 1 0 0 --- Bottom
1 0 0 0 --- Top
P2 – 1000 = 30 / 35
y = y1 + m(x-x1)
= 15 + 0.85 (50 – 40)
= 23.565
(x, y) = (50, 23.5)
x = x1 + 1/m (y -y1)
= 75 + 1/0.85 (40 – 45)
= 69.2
(x, y) = (69.2, 40)
Case 1: Case 2:
V2
V2
V1 V1
Case 3: Case 4:
V2
V1
V2
V1
Example: V4
V2 V3
V5
V1
Left Boundary
Consider the edge V1V2 -> Consider the intersecting pointV1’, so
processing for the first time need to store V1
edge V1V2 -> V1V1’ V4
V1’
V1
Right Boundary
edge V1V1’ -> V1V1’ V4
V1
Bottom Boundary
edge V1V1’ -> save nothing V4