Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
99 views10 pages

Cohen-Sutherland Line Clipping Guide

The Cohen-Sutherland algorithm clips lines to a rectangular viewport by assigning region codes to line endpoints based on whether they are left, right, above, or below the viewport. It then determines if lines can be trivially accepted or rejected, or if clipping is needed by performing logical operations on the endpoints' region codes. If clipping is required, it finds the intersection point of the line with the viewport boundary and uses that point to replace the outside endpoint and update its region code, repeating until the line is fully inside or outside the viewport.

Uploaded by

raji thangu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views10 pages

Cohen-Sutherland Line Clipping Guide

The Cohen-Sutherland algorithm clips lines to a rectangular viewport by assigning region codes to line endpoints based on whether they are left, right, above, or below the viewport. It then determines if lines can be trivially accepted or rejected, or if clipping is needed by performing logical operations on the endpoints' region codes. If clipping is required, it finds the intersection point of the line with the viewport boundary and uses that point to replace the outside endpoint and update its region code, repeating until the line is fully inside or outside the viewport.

Uploaded by

raji thangu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Cohen-Sutherland Line Clipping

-
Introduction
The Algorithm
• The Cohen–Sutherland algorithm is
a computer-graphics algorithm used for line
clipping. The algorithm divides a two-
dimensional space into 9 regions and then
efficiently determines the lines and portions
of lines that are visible in the central region of
interest (the viewport). The algorithm was
developed in 1967 during flight-simulator
work by Danny Cohen and Ivan Sutherland.
Cases while Clipping Line
Case A: Both the end points are inside the
window so no clipping needed.
Case B&D: A part of line is partially inside the
window, then the one outside is clipped.
Case C: If both end points are outside, then line
is rejected.
REGION CODES

1. Encode end points Bit 0 = point is left of


window
2. Bit 1 = point is right of window
3. Bit 2 = point is below window
4. Bit 3 = point is above window
Trivial Acceptance or Rejection of a Line Segment

Both endpoints of segment AB lie within the window, so the


whole segment AB must lie within the window.
Therefore, AB can be trivially accepted.
Both endpoints of segment CD lie entirely to one side of the
window, so segment CD must lie entirely outside of the window.
Therefore, CD can be trivially rejected.
Steps for Cohen-Sutherland 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.

You might also like