Here I have uploaded the Cohen Sutherland line clipping algorithm. Hopefully, it will help those who are trying to understand in the simplest way and need a presentation slide.
-Thanks
Tawfiq Ahmed
2. Introduction
ï§ When drawing a 2D line on screen, it might
happen that one or both endpoints are
outside the screen while a part of the line
should still be visible. In that case, an
efficient algorithm is needed to find two new
endpoints that are on the edges on the
screen, so that the part of the line that's
visible can now be drawn. This way, all those
points of the line outside the screen are
clipped away and don't need to waste any
execution time on them.
3. Here are a few cases, where the black rectangle represents the screen, in red are the
old endpoints, and in blue the ones after clipping:
ï§ Case A: Both endpoints are inside the screen, so no clipping needed.
ï§ Case B: One end-point outside the screen, that one had to be clipped.
ï§ Case C: both endpoints are outside the screen, and no part of the line is visible,
don't draw it at all.
ï§ Case D: both endpoints are outside the screen, and a part of the line is visible, clip
both endpoints and draw it.
4. How Cohen
Sutherland
Clipping
Algorithm
works.
ï§ 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 to the clipping
rectangle. It concerns itself with performing
the simple cases quickly.
ï§ In this algorithm it divides lines & edges into
2 cases.
1) Trivially Accept
2) Trivially Reject.
5. ï§ 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.
6. ï§ Xmin †X †Xmax
ï§ Ymin †Y †Ymax
ï§ Lines fulfill these conditions then
we will mark
ï§ those lines as trivially accept.
9. 1. The center region is the screen or Window
Position (0000).
2. If the region is above the screen, the first
bit is 1.
3. If the region is below the screen, the
second bit is 1.
4. If the region is to the right of the screen,
the third bit is 1.
5. If the region is to the left of the screen, the
fourth bit is 1.
10.
11. Then we have the final line after clipping is CD