Cohen-Sutherland Line Clipping Algorithm
-
Upload
maruf-abdullah-rion -
Category
Engineering
-
view
96 -
download
1
Transcript of Cohen-Sutherland Line Clipping Algorithm
![Page 1: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/1.jpg)
WELCOME TO OUR PRESENTATION
![Page 2: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/2.jpg)
Group 3
Cohen-Sutherland Line Clipping
Algorithm
![Page 3: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/3.jpg)
Hosted By
M.M. Arifin Ferdous Joy 131-15-2614
Md. Touhidul Hasan Shadi 132-15-2680
Maruf Abdullah (Rion) 132-15-2703
![Page 4: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/4.jpg)
Introduction
When drawing a 2D line on screen, it might happen that one or both of the 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 you don't need to waste any execution time on them.
A good clipping algorithm is the Cohen-Sutherland algorithm for this solution.
![Page 5: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/5.jpg)
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 end-points are inside the screen, so no clipping needed.
CASE A
![Page 6: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/6.jpg)
Case B: One end-point outside the screen, that one had to be clipped.
Case C: both endpoint are outside the screen, and no part of the line is visible, don't draw it at all.
Case D: both endpoint are outside the screen, and a part of the line is visible, clip both endpoints and draw it.
CASE B CASE C CASE D
![Page 7: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/7.jpg)
Cohen Sutherland Clipping Algorithm
Now we will learn what is Cohen Sutherland Clipping Algorithm and how it works.
This algorithm clips a line to the clipping rectangle. It concerns itself with performing the simple cases quickly.
![Page 8: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/8.jpg)
In this algorithm it divides lines & edges into 2 cases.
1) Trivially Accept and2) Trivially Reject.
![Page 9: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/9.jpg)
Conditions of Trivially Accept
Xmin ≤ X ≤ Xmax
Ymin ≤ Y ≤ Ymax
Lines fulfill this conditions then we will mark those lines as trivially accept.
Ymax
Ymin
Xmin Xmax
![Page 10: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/10.jpg)
Conditions of Trivially Reject
X0 < Xmin & X1 < Xmin or Y0 < Ymin & Y1 < Ymin
X0 > Xmax & X1 > Xmax orY0 > Ymax & Y1 > Ymax
![Page 11: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/11.jpg)
Question Arrives
We must have a question now??
A
B
Then we will move forward for solve this ……..
![Page 12: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/12.jpg)
The algorithm divides the 2D space in 9 regions:
This is also known as ABRL CODE
Figure: 2D space in 9 regions
![Page 13: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/13.jpg)
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.
![Page 14: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/14.jpg)
A (0100) B (0010)
AND Operation
Then get the new point C (0000)
![Page 15: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/15.jpg)
C (0000) B (0010)
AND Operation
Then get the new point D (0000)
Then we have the final line after clipping is CD
![Page 16: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/16.jpg)
Handling Similar Situations
If similar problems arrive then we have to clip those according to mentioned method.
Some examples of similar situations
![Page 17: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/17.jpg)
Any Questions??
![Page 18: Cohen-Sutherland Line Clipping Algorithm](https://reader035.fdocuments.us/reader035/viewer/2022062216/55d2bacabb61eb552b8b459a/html5/thumbnails/18.jpg)
Thanks a Lot