![Page 1: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/1.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
ClippingLecture 10
Sections 7.4 - 7.7
Robb T. Koether
Hampden-Sydney College
Fri, Sep 18, 2009
![Page 2: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/2.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Outline
1 ClippingPointsLinesPolygons
2 The Cohen-Sutherland Algorithm
3 Assignment
![Page 3: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/3.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping
An object whose coordinates are not entirely within therange of the clipping frustum must be clipped.That is, the part that is outside the frustum must beeliminated before the object is drawn.Why is it necessary to clip?
![Page 4: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/4.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping
There are three types of object to clip.PointsLinesPolygons
We will study a simple case of clipping lines in detail.
![Page 5: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/5.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Points
Clipping points is simpler than clipping lines.If the point is outside the frustum, clip it.If the point is inside the frustum, do not clip it.
This is done in clip coordinates where the point(x, y, z, w) is inside the frustum if and only if
−w ≤ x ≤ w−w ≤ y ≤ w−w ≤ z ≤ w
![Page 6: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/6.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Points
P(x, y, z, w)
Q(x, y, z, w)
(f, f, f, f)
(n, -n, -n, n)
(n, n, -n, n)
(f, -f, f, f)
Frustum, right side, in clip coordinates.
![Page 7: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/7.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Lines
If a line is partially in the frustum, then we need torecalculate its endpoints.There are four possible cases.
The line is entirely within the frustum.The line is entirely outside the frustum.One endpoint is in and the other is out.Both endpoints are out, but the middle part is in.
![Page 8: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/8.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Lines
B
A
C
E
D
F
H
G
Before clipping
![Page 9: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/9.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Lines
B
A
C
E
D
F
H
G
After clipping
![Page 10: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/10.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clipping polygons requires that their edges be clippingby the line-clipping algorithm, and then new edges becreated.Keep in mind that OpenGL treats all polygons asthough they were convex.How does this make clipping more efficient?
![Page 11: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/11.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
PolygonClip Region
![Page 12: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/12.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clip the right edge
![Page 13: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/13.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clip the right edge
![Page 14: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/14.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clip the top edge
![Page 15: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/15.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clip the top edge
![Page 16: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/16.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clip the left edge
![Page 17: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/17.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clip the left edge
![Page 18: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/18.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clip the bottom edge
![Page 19: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/19.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
Clip the bottom edge
![Page 20: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/20.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
The clipped polygon
![Page 21: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/21.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Polygons
When an edge is clipped, a shade is assigned to thenew vertex by interpolating between the endpoints.These interpolated shades are used when the interiorof the polygon is shaded.
![Page 22: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/22.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Interpolating the Clipped Polygon
-4
3
-34
![Page 23: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/23.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Interpolating the Clipped Polygon
-4
3
-34
(5, -2)
(2, 3)
(-6, 0)
(-5, -2)
![Page 24: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/24.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Interpolating the Clipped Polygon
-4
3
-34
(5, -2)
(2, 3)
(-6, 0)
(-5, -2)
[1, 1, 0]
[0, 1, 0]
[0, 0, 1]
[1, 0, 0]
![Page 25: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/25.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Interpolating the Clipped Polygon
-4
3
-34
(5, -2)
(2, 3)
(-6, 0)
(-5, -2)
[1, 1, 0]
[0, 1, 0]
[0, 0, 1]
[1, 0, 0]
![Page 26: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/26.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Interpolating the Clipped Polygon
-4
3
-34
(5, -2)
(2, 3)
(-6, 0)
(-5, -2)
[1, 1, 0]
[0, 1, 0]
[0, 0, 1]
[1, 0, 0]
(-1, 3) (1.5, 3)
(-4, 1)
(-4, -2) (4, -2)
(4, 0)
![Page 27: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/27.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Interpolating the Clipped Polygon
-4
3
-34
(5, -2)
(2, 3)
(-6, 0)
(-5, -2)
[1, 1, 0]
[0, 1, 0]
[0, 0, 1]
[1, 0, 0]
(-1, 3) (1.5, 3)
(-4, 1)
(-4, -2) (4, -2)
(4, 0)
[1, 0.25, 0]
[1, 0.75, 0][0.83, 1, 0]
[0.33, 1, 0]
[0, 0.9, 0.1][0, 0.1, 0.9]
![Page 28: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/28.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Interpolating the Clipped Polygon
-4
3
-34
(-1, 3) (1.5, 3)
(-4, 1)
(-4, -2) (4, -2)
(4, 0)
[1, 0.25, 0]
[1, 0.75, 0][0.83, 1, 0]
[0.33, 1, 0]
[0, 0.9, 0.1][0, 0.1, 0.9]
![Page 29: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/29.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
Let the x-coordinates of the window boundaries bexmin and xmax and let the y-coordinates be ymin andymax.
ymin
ymax
xmaxxmin
![Page 30: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/30.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
For each point P we will define a codeword c3c2c1c0
consisting of 4 true/false values (bits).c3 = true if P is left of the window.c2 = true if P is above the window.c1 = true if P is right of the window.c0 = true if P is below the window.
How many different values are possible for a codeword?
![Page 31: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/31.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
How many different combinations of values are possiblefor the codewords of two endpoints of a segment?How do we compute a codeword?
![Page 32: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/32.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
Initialize the codeword to 0.Consider the vertical edge x = xmin.Compare the x-coordinate of P to xmin.If it is less than xmin, then “set” bit 3 of the codeword.if (p.x < xmin) codeword = 1 << 3;
Similar calculations comparing to ymax, xmax, andymin will set bits 2, 1, and 0, respectively.
![Page 33: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/33.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
After the codewords for both endpoints are computed,we divide the possibilities into three cases:
Trivial accept - both codewords are FFFF.Trivial reject - both codewords have T in the sameposition.Non-trivial - Investigate further.
![Page 34: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/34.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
What is the quickest way to separate these threecases?Use bitwise “and” and “or.”If codeword1 | codeword2 == 0, then we triviallyaccept.If codeword1 & codeword2 != 0, then we triviallyreject.
![Page 35: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/35.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
What about the third case?We clip against each edge of the window, in sequence,as necessary.After clipping against an edge, we may test again fortrivial accept or trivial reject before moving on to thenext edge.
![Page 36: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/36.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
ymin
ymax
xmaxxmin
![Page 37: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/37.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
ymin
ymax
xmaxxmin
Clip
![Page 38: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/38.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
ymin
ymax
xmaxxmin
Clip
![Page 39: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/39.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
ymin
ymax
xmaxxmin
Clip
![Page 40: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/40.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
ymin
ymax
xmaxxmin
Clip
![Page 41: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/41.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
ymin
ymax
xmaxxmin
![Page 42: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/42.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
This raises some questions?What is the worst case?What is the best case?How do we decide whether to clip against a particularedge?If we do clip, how to we determine the new endpoint?
![Page 43: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/43.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
Consider again the vertical edge x = xmin. (You cando the other edges.)Compute codeword1 ˆ codeword2.This shows where they disagree.“And” this with 1 << 3.If the result is not 0, then clip.Otherwise do not clip.
![Page 44: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/44.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
If we clip, then the new point will be on the linex = xmin.So its x-coordinate will be xmin.We must calculate its y-coordinate.
![Page 45: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/45.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
x = xmin
P
Q
R
![Page 46: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/46.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
x = xmin
P
Q
R
![Page 47: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/47.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
x = xmin
P
Q
R
Q.x - P.xR.x - P.x
Q.y - P.y
R.y - P.y
![Page 48: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/48.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
The Cohen-Sutherland Clipping Algorithm
Then, by similar triangles,
R.y − P.y
Q.y − P.y=
xmin− P.x
Q.x− P.x.
Therefore,
R.y = P.y + (Q.y − P.y)(
xmin− P.x
Q.x− P.x
).
![Page 49: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/49.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Clipping Lines
Example (Clipping Lines)The code.The executable.
![Page 50: Clipping - Lecture 10 Sections 7.4 - 7people.hsc.edu/faculty-staff/robbk/Coms331/Lectures/Lectures 2009... · The Cohen-Sutherland Algorithm Assignment The Cohen-Sutherland Clipping](https://reader030.vdocuments.mx/reader030/viewer/2022041019/5ecd18efbe20f52d853384e2/html5/thumbnails/50.jpg)
Clipping
Robb T.Koether
ClippingPoints
Lines
Polygons
The Cohen-SutherlandAlgorithm
Assignment
Homework
HomeworkRead Section 7.4 – Cohen-Sutherland clipping.Read Section 7.5 – polygon clipping.Read Section 7.6 – clipping other objects.Read Section 7.7 – 3D clipping.