COHEN SUTHERLAND LINE CLIPPING ALGORITHM
1. Read the coordinates of line and draw a line
2. Read the coordinates of window xwmin, xwmax, yxmin, ywmax and draw a
window
3. Generate a vector C which determines whether the point is right, left, bottom or top
to window
4. Left if x < style=""> c[0]=1 else c[0]=0
Right if x < style=""> c[1]=1 else c[1]=0
Bottom if x < style=""> c[2]=1 else c[2]=0
Top if x < style=""> c[3]=1 else c[3]=0
5. To determine whether the entire line is inside the window Logically Or the vector
if the result is Zero the line is fully inside the window
6. To determine whether the entire line is outside the window logically AND the vectors if
result is ONE then entire line lies outside the window
1. If portion of line outside the window calculate the point where it intersects window and
suitably swapping pointsand vectors using following
Left c[0] = 1 y = y1 + ( x - x1 ) * m; x=xwmin
Right c[1] = 1 y = y2 + ( x - x2 ) * m; x=xwmax
Bottom ` c[2] = 1 x = x1 + ( y - y1 ) / m; y=xwmin
. Top c[3] = 1 x = x1 + ( y - y2 ) / m; y=xwmax
2. Draw the line using new points
3. STOP
No comments:
Post a Comment