chi-cheng lin, winona state university cs430 computer graphics vectors part iv polygon intersection

19
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

Upload: bethanie-hart

Post on 17-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

Chi-Cheng Lin, Winona State University

CS430 Computer Graphics

Vectors Part IVPolygon Intersection

Page 2: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

2

Topics

Polygon Intersection Problems Convex Polygons and Polyhedra Ray Intersection and Clipping Cyrus-Beck Clipping Algorithm

Page 3: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

3

Polygon Intersection Problems

Polygons are fundamental objects in both 2D and 3D graphics

A polygonal mesh can be used to model a 3D graphics object

PolyhedronA polygonal mesh which forms a closed

surface that encloses some space

Page 4: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

4

Polygon Intersection Problems

Is a given point P inside or outside the object?

Where does a given ray R first intersect the object?

Which part of a given line L lies inside/outside the object?

Page 5: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

5

Polygon Intersection Problems

Page 6: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

6

Convex Polygons and Polyhedra

General case of polygon/polyhedron intersection problems is complex

Convex polygons/polyhedra are easier to deal with2D: a convex polygon can be completely

described by a set of “bounding lines”3D: a convex polyhedron can be

completely described by a set of “bounding planes”

Deal with bounding lines/planes

Page 7: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

7

Convex Polygons and Polyhedra

Page 8: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

8

Convex Polygons and Polyhedra

Outward normalEvery bounding line of a 2D convex

polygonEvery bounding plane of a 3D convex

polyhedron

Page 9: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

9

Convex Polygons and Polyhedra

Outside half-space

PolyhedronIntersection of all the inside half-spaces

L1

Outside half-spaceInside

half-space

Page 10: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

10

Ray Intersection A Intersection problem: when does

a ray enter and exit a convex polygon?

A ray A + ct hits a convex polygon P exactly twiceEntering hit point: A + ctin

Exiting hit point: A + ctout

The ray is inside P for all t [tin, tout]

Ac

P

Page 11: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

11

Clipping Clipping problem: given points A

and C, which part of line segment AC lies inside a convex polygon P ?

A’ = A + c max(0, tin)

C’ = A + c min(tout, 1)

A PC0 tin

tout 1

A0 tin

tout

C1

A0tin

tout

C1

Page 12: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

12

Clipping How are tin and tout computed?

We must find the intersection of the ray and each bounding line in turn

Assume a bounding line is represented as {B, n}, where B: some point on the linen: outward normal

Page 13: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

13

Clipping If nc > 0, ray is exiting from P

If nc = 0, ray is parallel to PIf nc < 0, ray is entering P

For each bounding line, findHit time of the ray with bounding lineWhether the ray is entering or exiting

n1

cA B1 B2

n2

Page 14: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

14

Clipping Approach

Candidate interval of t : [tin, tout ]Keep track of the maximum entering

time tin

Keep track of the minimum exit time tout

We want to chop the interval at each iteration

Can stop as soon as tin > tout (what does this mean?)

Page 15: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

15

Clipping - AlgorithmInitialize [tin, tout] [0, 1]

for each boundaryfind the hit time thit

if entering then tin = max(tin, thit)

else tout = min(tout, thit)

if tin > tout then no intersection stop

segment from A + ctin to A + ctout lies inside P

(We found: endpoints of clipped lines entering and exiting points of ray)

Page 16: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

16

Clipping - ExampleUpdates on tin and tout:

Line test tin tout

0 0 0.831 0 0.662 0 0.663 0 0.664 0.2 0.665 0.28 0.66

L0

L1

L2

L3

L4

L5 A

C

@0

@1

@.2

@[email protected]

@.83

@3.4

@-4.7

Page 17: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

17

Cyrus-Beck Clipping Algorithm Clip a line segment against any convex

polygon Input parameters

Line segmentList of bounding lines

Output parameterClipped line segment

Return value1, if part of segment lies in P0, otherwise

Page 18: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

18

Page 19: Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection

19