Point Clipping Algorithm in Computer Graphics: Week 15
Point Clipping Algorithm in Computer Graphics: Week 15
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.
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.
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:
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).
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.
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.