Any procedure that identifies those portions of a picture that are either inside or outside of a specified region or space is known as clipping.
Cohen-Sutherland line clipping Algorithm:
Generally, this method speeds up the processing of line segments, by performing initial tests that reduce the number of intersections that must be calculated. Every line endpoint in a picture is assigned a 4-digit binary code, called a region code that identifies the location of the point relative to the boundaries of the clipping rectangle.
Each bit position in the region code is used to indicate one of the four relative coordinate positions of the point with respect to the clip window: to the left, right, top, or bottom. By numbering the bit positions in the region code as 1 through 4 from right to left, the coordinate regions can be correlated with the bit position as:
Bit 1: left
Bit 2: right
Bit 3: below
Bit 4: above
A value of 1 in any bit position indicated that the point is in that relative position, otherwise, the bit position is set to 0. If a point is within the clipping rectangle, the region code is 0000. A point that is below & to the left of the rectangle has a region code of 0101.
Bit values in the region code are determined by comparing endpoint coordinate values (x, y) to the clip boundaries. Bit 1 is set 1 if x <xwmin. The other three bit values can be determined using similar comparisons.
Once we have established region codes for all line endpoints, we can quickly determine which lines are completely inside the clip window & which are clearly outside. Any lines that are completely contained within the window boundaries have a region code of 0000 for both endpoints.