0% found this document useful (0 votes)
8 views2 pages

Practical No 8

The document outlines the Cohen Sutherland line clipping algorithm, which categorizes the screen into 9 regions to determine the visibility of lines relative to a defined window. It details the steps for assigning region codes, performing logical operations to check visibility, and calculating intersections with the window boundaries. The process continues until the line is fully clipped or determined to be invisible.

Uploaded by

vinitdevadiga647
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)
8 views2 pages

Practical No 8

The document outlines the Cohen Sutherland line clipping algorithm, which categorizes the screen into 9 regions to determine the visibility of lines relative to a defined window. It details the steps for assigning region codes, performing logical operations to check visibility, and calculating intersections with the window boundaries. The process continues until the line is fully clipped or determined to be invisible.

Uploaded by

vinitdevadiga647
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/ 2

Practical no 8

Title: Apply clipping algorithms on graphical objects.


Aim: Implement Line Clipping Algorithm: Cohen Sutherland
Theory:
n this algorithm, we are given 9 regions on the screen. Out of which one region is of the window
and
the rest 8 regions are around it given by 4 digit binary. The division of the regions are based on
(x_max,
y_max) and (x_min, y_min).
The central part is the viewing region or window, all the lines which lie within this region are
completely
visible. A region code is always assigned to the endpoints of the given line.
Algorithm
Steps
1) Assign the region codes to both endpoints.
2) Perform OR operation on both of these endpoints.
3) if OR = 0000,
then it is completely visible (inside the window).
else
Perform AND operation on both these endpoints.
i) if AND ≠ 0000,
then the line is invisible and not inside the window. Also, it can’t be considered

for clipping.
ii) else
AND = 0000, the line is partially inside the window and considered for clipping.
4) After confirming that the line is partially inside the window, then we find the intersection with
the boundary of the window. By using the following formula:-
Slope:- m= (y2-y1)/(x2-x1)

a) If the line passes through top or the line intersects with the top boundary of the window.

x = x + (y_wmax – y)/m
y = y_wmax

b) If the line passes through the bottom or the line intersects with the bottom boundary of the
window.

x = x + (y_wmin – y)/m
y = y_wmin

c) If the line passes through the left region or the line intersects with the left boundary of the
window.
y = y+ (x_wmin – x)*m
x = x_wmin

d) If the line passes through the right region or the line intersects with the right boundary of the
window.

y = y + (x_wmax -x)*m
x = x_wmax

5) Now, overwrite the endpoints with a new one and update it.
6) Repeat the 4th step till your line doesn’t get completely clipped

You might also like