clipping ( cohen-sutherland algorithm )
TRANSCRIPT
![Page 1: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/1.jpg)
clipping (Cohen-Sutherland Algorithm)
JMHM Jayamaha SEU/IS/10/PS/104
PS0372
![Page 2: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/2.jpg)
Content What is Clipping ?.
Point clipping Line clipping
Cohen-Sutherland Algorithm
![Page 3: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/3.jpg)
What is Clipping ? Any Procedure that identifies those portions of a picture that are
either inside or outside of a specified region of a space is referred to as a Clipping algorithm or simply Clipping.
The primary use of clipping in computer graphics is to remove objects, lines, or line segments that are outside the viewing pane.
![Page 4: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/4.jpg)
Point Clipping Clipping a point from a given window is very easy. Consider the
following figure, where the rectangle indicates the window. Point clipping tells us whether the given point (X, Y) is within the given window or not; and decides whether we will use the minimum and maximum coordinates of the window.
The X-coordinate of the given point is inside the window, if X lies in between Wx1 ≤ X ≤ Wx2. Same way, Y coordinate of the given point is inside the window, if Y lies in between Wy1 ≤ Y ≤ Wy2.
![Page 5: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/5.jpg)
Line Clipping The concept of line clipping is same as point clipping. In line clipping,
we will cut the portion of line which is outside of window and keep only the portion that is inside the window.
![Page 6: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/6.jpg)
Cohen-Sutherland Algorithm eliminate as many cases as possible without computing intersections
Start with four lines that determine the sides of the clipping window
![Page 7: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/7.jpg)
The Cases Case 1: both endpoints of line segment inside all four lines
Draw (accept) line segment as is
Case 2: both endpoints outside all lines and on same side of some line Discard (reject) the line segment
![Page 8: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/8.jpg)
The Cases Case 3: One endpoint inside, one outside
Must do at least one intersection Case 4: Both outside all lines but not on same side of any line
May have part inside Must do at least one intersection
![Page 9: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/9.jpg)
Defining Outcodes b0 b1 b2 b3
b0 = 1 if y > ymax, 0 otherwiseb1 = 1 if y < ymin, 0 otherwiseb2 = 1 if x > xmax, 0 otherwiseb3 = 1 if x < xmin, 0 otherwise
![Page 10: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/10.jpg)
Defining Outcodes For each endpoint, define an outcode
Outcodes divide space into 9 regions
![Page 11: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/11.jpg)
Algorithm
![Page 12: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/12.jpg)
Using Outcodes Consider the 5 cases below AB: outcode(A) = outcode(B) = 0
Accept line segment
![Page 13: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/13.jpg)
Using Outcodes CD: outcode (C)= 0, outcode(D)=0010≠ 0
Compute intersection Location of 1 in outcode(D) determines which edge to intersect with Note if there were a segment from A to a point in a region with 2 ones in
outcode, we might have to do two interesections
![Page 14: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/14.jpg)
Using Outcodes EF: outcode(E) logically AND ed with outcode(F) (bitwise) ≠ 0
Both outcodes have a 1 bit in the same place Line segment is outside of corresponding side of clipping window reject
![Page 15: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/15.jpg)
Using Outcodes GH and IJ: same outcodes, neither zero but logical AND yields zero Shorten line segment by intersecting with one of sides of window Compute outcode of intersection (new endpoint of shortened line
segment) Reexecute algorithm
![Page 16: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/16.jpg)
Efficiency In many applications, the clipping window is small relative to the size
of the whole data base Most line segments are outside one or more side of the window and can be
eliminated based on their outcodes
Inefficiency when code has to be reexecuted for line segments that must be shortened in more than one step
![Page 17: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/17.jpg)
Summary Clipping is the method of cutting a graphics display to neatly fit a
predefined graphics region or view port. Cohen-Sutherland algorithm
![Page 18: Clipping ( Cohen-Sutherland Algorithm )](https://reader037.vdocument.in/reader037/viewer/2022102917/58705bdc1a28aba2118b69ff/html5/thumbnails/18.jpg)
References http://www.tutorialspoint.com/computer_graphics/
viewing_and_clipping.htm http://www.cs.kent.edu/~farrell/cg05/lectures/cg25.pdf https://www.youtube.com/watch?v=dQNTyVLDP5Q