1
73kviews
Explain cohen Sutherland line clipping algorithm in detail

Mumbai University > Computer Engineering > Sem 4 > Computer Graphics

Marks: 10 Marks

Year: May 2016

1 Answer
14
4.1kviews

Line Clipping:

The concept of line clipping is same as point clipping. In line clipping, we will cut the portion of line which is outside of window and keep only the portion that is inside the window.

Cohen-Sutherland Line Clippings:

  • This algorithm uses the clipping window as shown in the following figure. The minimum coordinate for the clipping region is( XW$_m$$_i$$_n$,YW$_m$$_i$$_n$)(XW$_m$$_i$$_n$,YW$_m$$_i$$_n$) and the maximum coordinate for the clipping region is (XW$_m$$_a$$_x$,YW$_m$$_a$$_x$)(XW$_m$$_a$$_x$,YW$_m$$_a$$_x$).

    enter image description here

  • We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom, Right, and Left of the region as shown in the following figure. Here, the TOP and LEFT bit is set to 1 because it is the TOP-LEFT corner.

    enter image description here

  • There are 3 possibilities for the line:

  • Line can be completely inside the window (This line should be accepted).

  • Line can be completely outside of the window (This line will be completely removed from the region).

  • Line can be partially inside the window (We will find intersection point and draw only that portion of line that is inside region).

Algorithm:

Step 1 − Assign a region code for each endpoints.

Step 2 − If both endpoints have a region code 0000 then accept this line.

Step 3 − Else, perform the logical ANDoperation for both region codes.

Step 3.1 − If the result is not 0000, then reject the line.

Step 3.2 − Else you need clipping.

Step 3.2.1 − Choose an endpoint of the line that is outside the window.

Step 3.2.2 − Find the intersection point at the window boundary (base on region code).

Step 3.2.3 − Replace endpoint with the intersection point and update the region code.

Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially accepted or trivially rejected.

Step 4 − Repeat step 1 for other lines.

Conclusion:

In summary, the C-S algorithm is efficient when outcode testing can be done cheaply (for example, by doing bitwise operations in assembly language) and trivial acceptance or rejection is applicable to the majority of line segments .(For example, large windows - everything is inside , or small windows - everything is outside).

Please log in to add an answer.