Cohen Sutherland Algorithm
Cohen Sutherland Algorithm
Shubhangi Shinde
Clipping
Why clipping?
Not everything defined in the world coordinates is inside the world window
Line Clipping
Visible : Both end points of the line segment lie within the window. Non-visible: When line definitely lies outside the window. This will occur if line segment satisfy
X1,x2,>xmax y1,y2 >ymax X1,x2<xmin y1,y2<ymin
Partially visible: A line is partially visible when a part of its lies within the window.
1000 0000
Window
0001 0101
0100
Otherwise
Clip against each edge in turn Throw away clipped off part of line each time
L2
L3 L1 L5
L6
1st Bit : Point lies to left of window x<xmin 2nd bit : point lies to right of window x>xmax 3rd bit : point lies below of window y<ymin 4th bit : piont lies above window y>ymax.
outcode[1] (x < Window.left) outcode[2] (y > Window.top) outcode[3] (x > Window.right) outcode[4] (y < Window.bottom)
L2
L3
L6
11
Cohen-Sutherland: Labelling
Every end-point is labelled with the appropriate region code
P4 [1000] P11 [1010]
wymax
P3 [0001]
Window
P6 [0000] P5 [0000] P7 [0001] P9 [0000] P12 [0010] P8 [0010] P10 [0100]
wymin
P13 [0101]
P14 [0110]
wxmin
wxmax
wymax
P3 [0001]
Window
P6 [0000] P5 [0000] P7 [0001] P9 [0000] P12 [0010] P8 [0010] P10 [0100]
wymin
P13 [0101]
P14 [0110]
wxmin
wxmax
Cohen-Sutherland: Lines Outside The Window Any lines with a common set bit in the region codes of both end-points can be clipped
The AND operation can efficiently check this
P4 [1000] P11 [1010]
wymax
P3 [0001]
Window
P6 [0000] P5 [0000] P7 [0001] P9 [0000] P12 [0010] P8 [0010] P10 [0100]
wymin
P13 [0101]
P14 [0110]
wxmin
wxmax
We can use the region codes to determine which window boundaries should be considered for intersection
To check if a line crosses a particular boundary we compare the appropriate bits in the region codes of its end-points If one of these is a 1 and the other is a 0 then the line crosses the boundary
Cohen-Sutherland Examples
Consider the line P9 to P10 below
Start at P10 Window wymax From the region codes of the two end-points we know the line doesnt P [0000] cross the left or right wymin P [0000] boundary P [0100] Calculate the wxmin wxmax intersection of the line with the bottom boundary to generate point P10 The line P9 to P10 is completely inside the window so is retained
9 10 10
wymin
wxmin
wxmax
Window
wymin
wxmin
wxmax
wymin
wxmin
wxmax