50
Clipping Robb T. Koether Clipping Points Lines Polygons The Cohen- Sutherland Algorithm Assignment Clipping Lecture 10 Sections 7.4 - 7.7 Robb T. Koether Hampden-Sydney College Fri, Sep 18, 2009

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

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.