190 likes | 296 Views
CS430 Computer Graphics. Vectors Part IV Polygon Intersection. Topics. Polygon Intersection Problems Convex Polygons and Polyhedra Ray Intersection and Clipping Cyrus-Beck Clipping Algorithm. Polygon Intersection Problems. Polygons are fundamental objects in both 2D and 3D graphics
E N D
CS430 Computer Graphics Vectors Part IV Polygon Intersection Chi-Cheng Lin, Winona State University
Topics • Polygon Intersection Problems • Convex Polygons and Polyhedra • Ray Intersection and Clipping • Cyrus-Beck Clipping Algorithm
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 • Polyhedron • A polygonal mesh which forms a closed surface that encloses some space
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?
Convex Polygons and Polyhedra • General case of polygon/polyhedron intersection problems is complex • Convex polygons/polyhedra are easier to deal with • 2D: 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
Convex Polygons and Polyhedra • Outward normal • Every bounding line of a 2D convex polygon • Every bounding plane of a 3D convex polyhedron
Convex Polygons and Polyhedra • Outside half-space • Polyhedron • Intersection of all the inside half-spaces Outside half-space Inside half-space L1
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 twice • Entering hit point: A + ctin • Exiting hit point: A + ctout • The ray is inside P for all t [tin, tout] c A P
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) tout tout 1 1 tin 0 tin C 0 C A A P tout 1 tin 0 C A
Clipping • How aretin 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 line • n: outward normal
Clipping • If nc > 0, ray is exiting from P If nc = 0, ray is parallel to P If nc < 0, ray is entering P • For each bounding line, find • Hit time of the ray with bounding line • Whether the ray is entering or exiting n1 n2 c B1 B2 A
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?)
Clipping - Algorithm Initialize [tin, tout] [0, 1] for each boundary find 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)
Clipping - Example Updates on tin and tout: Line test tintout 0 0 0.83 1 0 0.66 2 0 0.66 3 0 0.66 4 0.2 0.66 5 0.28 0.66 @0 L5 @.2 L0 A @.28 @.83 @1 @.66 L4 C L1 @-4.7 @3.4 L3 L2
Cyrus-Beck Clipping Algorithm • Clip a line segment against any convex polygon • Input parameters • Line segment • List of bounding lines • Output parameter • Clipped line segment • Return value • 1, if part of segment lies in P • 0, otherwise