Cohen sutherland line clipping algorithm

TawfiqAhmed2 626 views 12 slides Jun 02, 2020
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

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


Slide Content

Cohen-Sutherland Line Clipping Algorithm

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.

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.

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. Trivially Accept Trivially Reject.

Trivial Acceptance or Rejection 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.

Conditions of Trivially Accept Xmin ≤ X ≤ Xmax Ymin ≤ Y ≤ Ymax Lines fulfill these conditions then we will mark those lines as trivially accept.

Conditions of Trivially Reject X0 < Xmin & X1 < Xmin or Y0 < Ymin & Y1 < Ymin X0 > Xmax & X1 > Xmax or Y0 > Ymax & Y1 > Ymax

The algorithm divides the 2D space in 9 region This is also known as ABRL code.

The center region is the screen or Window Position (0000). If the region is above the screen, the first bit is 1. If the region is below the screen, the second bit is 1. If the region is to the right of the screen, the third bit is 1. If the region is to the left of the screen, the fourth bit is 1.

Then we have the final line after clipping is CD

Thank You