100% found this document useful (1 vote)
909 views6 pages

Cohen-Sutherland Line Clipping Algorithm

The Cohen-Sutherland line clipping algorithm clips lines to the boundaries of a viewing window. It works by calculating the intersection points of the line with each boundary and clipping the line endpoints accordingly. There are 4 boundary cases - left, right, bottom, top - determined by a bit code for each line endpoint. The algorithm uses the line slope and boundary intersections to calculate new clipped endpoint coordinates.

Uploaded by

Siddhartha B S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
100% found this document useful (1 vote)
909 views6 pages

Cohen-Sutherland Line Clipping Algorithm

The Cohen-Sutherland line clipping algorithm clips lines to the boundaries of a viewing window. It works by calculating the intersection points of the line with each boundary and clipping the line endpoints accordingly. There are 4 boundary cases - left, right, bottom, top - determined by a bit code for each line endpoint. The algorithm uses the line slope and boundary intersections to calculate new clipped endpoint coordinates.

Uploaded by

Siddhartha B S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 6

Cohen-Sutherland Line Clipping Algorithm

1001 1000 1010

0001 0000 0010


0000

0101 0100 0110

b4 b3 b2 b1
0 0 0 1 --- Left
0 0 1 0 --- Right
0 1 0 0 --- Bottom
1 0 0 0 --- Top

If one of point is non zero & logical AND is zero


a. One of p1 & p2 is zero
b. Both non zero & logical AND is zero
Y value of vertical lines
Consider (x1, y1) (x2, y2)
Intersecting point (x, y)
Slope m= (y - y1) / (x - x1)
xmin xmax
 y - y1 = m (x - x1)
 y = y1 + m (x - x1) x = xmin –> left border
x = xmax -> right border
x values of horizontal lines
Consider (x1, y1) (x2, y2)
Intersecting point (x, y)
Slope m= (y - y1) / (x - x1) xmin xmax
 x - x1= (y - y1) / m
 x = x1 + (y - y1) / m
y = ymin –> bottom border
y = ymax -> upper(top) border
Logical AND operation m = (y2-y1) / (x2-x1)

P1 – 0001 = (45-15) / (75-40)

P2 – 1000 = 30 / 35

0000 – zero = 0.85

Intersecting Point is (x,y)


Xwmin = 50 Xwmax = 80
Ywmin = 10 Ywmax = 40

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

edge V2V3 -> V2’V3


edge V3V4 -> V4
V2’
edge V4V5 -> V5 V3
V5
edge V5V1 -> V1

V1’

V1
Right Boundary
edge V1V1’ -> V1V1’ V4

edge V1’V2’ -> V2’


edge V2’V3 -> V3
V2’
edge V3V4 ->V4 V3
V5
edge V4V5 -> V5
edge V5V1 -> V1
V1’

V1

Bottom Boundary
edge V1V1’ -> save nothing V4

edge V1’V2’ -> V1”V2


edge V2’V3 -> V3
V2’
edge V3V4 ->V4 V3
V5
edge V4V5 -> V5
V1’’
edge V5V1 -> V5’
V5’
Upper (Top) Boundary
edge V1”V2’ -> V1”V2’
V3’ V4’
edge V2’V3 -> V3
edge V3V4 ->V3’
V2’
edge V4V5 -> V4’V5 V3
V5
edge V5V5’ -> V5’
V1’’
edge V5’V1” -> V1”
V5’

You might also like