0% found this document useful (0 votes)
777 views6 pages

Point Clipping Algorithm in Computer Graphics: Week 15

The document discusses the Cohen-Sutherland line clipping algorithm in computer graphics. It divides the 2D space into 9 regions, with only the middle region visible. The algorithm uses outcodes to test for trivial acceptance or rejection of line segments. If not trivially accepted or rejected, it divides the line into segments at the clip edge and iteratively clips them until fully inside or rejected. It is efficient when outcode testing is fast and many lines can be trivially accepted or rejected.

Uploaded by

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

Point Clipping Algorithm in Computer Graphics: Week 15

The document discusses the Cohen-Sutherland line clipping algorithm in computer graphics. It divides the 2D space into 9 regions, with only the middle region visible. The algorithm uses outcodes to test for trivial acceptance or rejection of line segments. If not trivially accepted or rejected, it divides the line into segments at the clip edge and iteratively clips them until fully inside or rejected. It is efficient when outcode testing is fast and many lines can be trivially accepted or rejected.

Uploaded by

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

WEEK 15

Point Clipping Algorithm in Computer Graphics


Clipping: In computer graphics our screen act as a 2-D coordinate system. it is not necessary
that each and every point can be viewed on our viewing pane(i.e. our computer screen). We can
view points, which lie in particular range (0,0) and (Xmax, Ymax). So, clipping is a procedure
that identifies those portions of a picture that are either inside or outside of our viewing pane.
In case of point clipping, we only show/print points on our window which are in range of our
viewing pane, others points which are outside the range are discarded.
Example

Point Clipping Algorithm:


1. Get the minimum and maximum coordinates of both viewing pane.
2. Get the coordinates for a point.
3. Check whether given input lies between minimum and maximum coordinate of viewing
pane.
4. If yes display the point which lies inside the region otherwise discard it.
Line Clipping

In computer graphics, line clipping is the process of removing lines or portions of lines outside an
area of interest. Typically, any line or part thereof which is outside of the viewing area is
removed.
There are two common algorithms for line clipping: Cohen–Sutherland and Liang–Barsky.
A line-clipping method consists of various parts. Tests are conducted on a given line segment to
find out whether it lies outside the view volume. Afterwards, intersection calculations are carried
out with one or more clipping boundaries.[1]
Determining which portion of the line is inside or outside of the clipping volume is done by
processing the endpoints of the line with regards to the intersection.
Cohen–Sutherland
In computer graphics, the Cohen–Sutherland algorithm (named after Danny Cohen and Ivan
Sutherland) is a line-clipping algorithm. The algorithm divides a 2D space into 9 regions, of
which only the middle part (viewport) is visible.

Steps for Cohen-Sutherland algorithm

1. End-points pairs are check for trivial acceptance or trivial rejected using
the outcode.
2. If not trivial-accepance or trivial-rejected, divided into two segments at
a clip edge.
3. Iteratively clipped by testing trivial-acceptance or trivial-rejected, and
divided into two segments until completely inside or trivial-rejected.

Pseudo-code of Cohen-Sutherland Algorithm.

Trivial acceptance/reject test

To perform trivial accept and reject tests, we extend the edges of the clip rectangle to divide the
plane of the clip rectangle into nine regions. Each region is assigned a 4-bit code deteermined by
where the region lies with respect to the outside halfplanes of the clip-rectangle edges. Each bit in
the outcode is set to either 1 (true) or 0 (false); the 4 bits in the code correspond to the following
conditions:

o Bit 1 : outside halfplane of top edge, above top edge


Y > Ymax
o Bit 2 : outside halfplane of bottom edge, below bottom edge
Y < Ymin
o Bit 3 : outside halfplane of right edge, to the right of right edge
X > Xmax
o Bit 4 : outside halfplane of left edge, to the left of left edge
X < Xmin

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).

Cohen Sutherland Line Clipping Algorithm:


In the algorithm, first of all, it is detected whether line lies inside the screen or it is
outside the screen. All lines come under any one of the following categories:

1. Visible
2. Not Visible
3. Clipping Case

1. Visible: If a line lies within the window, i.e., both endpoints of the line lies
within the window. A line is visible and will be displayed as it is.
2. Not Visible: If a line lies outside the window it will be invisible and rejected.
Such lines will not display. If any one of the following inequalities is satisfied, then
the line is considered invisible. Let A (x1,y2) and B (x2,y2) are endpoints of line.

xmin, xmax are coordinates of the window.

ymin,ymax are also coordinates of the window.


x1>xmax
x2>xmax
y1>ymax
y2>ymax
x1<xmin
x2<xmin
y1<ymin
y2<ymin

4. Clipping Case: If the line is neither visible case nor invisible case. It is
considered to be clipped case. First of all, the category of a line is found
based on nine regions given below. All nine regions are assigned codes. Each
code is of 4 bits. If both endpoints of the line have end bits zero, then the
line is considered to be visible.

The center area is having the code, 0000, i.e., region 5 is considered a rectangle window.

Line AB is the visible case


Line OP is an invisible case
Line PQ is an invisible line
Line IJ is an invisible line
Line MN are clipping candidate
Line CD are clipping candidate

Advantage of Cohen Sutherland Line Clipping:


It calculates end-points very quickly and rejects and accepts lines quickly.

You might also like