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 Clipping Algorithm
This algorithm uses the clipping window as shown in the following figure. The minimum coordinate for the clipping region is (XWmin,YWmin) and the maximum coordinate for the clipping region is (XWmax,YWmax).
We will use 4-bits to divide the entire region. These 4 bits represent TBRL (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.
There are 3 possibilities for the line −
  • Line can be completely inside the window (This line will be completely removed from the region).
  • 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).

No comments:

Post a Comment