Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Polygon Interception: Cyrus Beck Algorithm Mengxia Zhu Fall 2007.

Similar presentations


Presentation on theme: "Ray Polygon Interception: Cyrus Beck Algorithm Mengxia Zhu Fall 2007."— Presentation transcript:

1 Ray Polygon Interception: Cyrus Beck Algorithm Mengxia Zhu Fall 2007

2 Polygon and Polyhedron Polygon and Polyhedron are fundamental objects in 2D or 3D graphics. In 2D, straight lines make a polygon, in 3D, an object if often modeled as a polygonal “mesh”: a collection of polygons that fit together. If the skin forms a closed surface, the mesh is called polyhedron. P

3 Ray Polygon Intersection In order to analyze or render them, we usually need to solve the intersection problem. The general case of intersecting a line with a polygon and polyhedron is quite complex. We study convex forms with bounding lines or bounding planes first. Solve how a ray intersects a convex polygon or convex polyhedron is an essential technique in viewing 3D objects.  Is a given point P inside or outside the object  Where does a given ray first intersect the object  Which part of a given line lies inside the object?

4 Ray Casting Ray Tracing examples www.geocities.com/.../ coolhead1small2rot.png www-evasion.imag.fr/.../ecs177.html

5 Parametric Line Revisited P 0 is the starting point P 1 another point on the line P linear interpolation between P 0 and P 1 Affine combination, Convex combination

6 Dot Product Revisited

7 Point inside or outside?

8 Direction for Ray that Strikes Plane the ray is aimed “along with” the normal the ray is parallel to the plane the ray is aimed “counter to” the normal r n r

9 Cyrus-Beck Algorithm Developed by Cyrus and Beck in 1978 Clip line against convex polygon/polyhedron Completely described by a set of “bounding lines or planes” Find a value of t for intersection of line and clipping edges. Use simple comparison of t values to find actual clipping segment.

10 Where a Ray intersects a line(2D) or plane(3D) A point normal form of edge or plane A parametric equation of line: Find t such that PLPL NLNL P(t) Inside Outside

11 Cyrus-Beck Algorithm (Cont’) Classify the relative position of the ray to intercepting edge or plane  If: ray parallel to the edge of line or plane  If: ray exiting polygon  If : ray entering polygon Entering Exiting P1 P0

12 Each Bounding Line or Plane We should find:  The hit time of the ray with the bounding line or bounding plane  Whether the ray is entering or exiting the polygon or polyhedron.

13 Compute PE with largest t: max (t in, 0) Compute PL with smallest t: min ( t out, 1) Clip to these two points Cyrus-Beck Algorithm (Cont’) PE PL P1P1 PE P0P0

14 Cyrus-Beck Algorithm (Cont’) Initialize the candidate interval to [0,1] For each bounding line, find the hit time of t hit and determine whether it is an entering or exiting hit  If t_ hit is an entering hit, set t_ in = max (t in, t hit )  If t_ hit is an exiting hit, set t_ out = min (t out, t hit ) If at any point tin becomes greater than t_out, the ray misses P entirely, and testing is terminated. If the candidate interval is not empty, then the segment between tin and tout lies inside P.

15 Clipping Against Arbitrary Polygons Polygon is no longer bounded by a collection of infinite bounding lines in point normal form. We have to work with N finite segments P1 P2

16 Clipping Against Arbitrary Polygons Represent edge of P parametrically  For example, segment P 3 P 4 is represented as: P 3 + e 3* u, where e 3 =P 4 -P 3, u ranges from 0 to 1.  Ray intersection with above segment is represented as: R + c*t = P 3 + e 3* u Find all of the hits of the ray with all edges of P and place them in a list of the hit times. The smallest value of t in hit-list is the first hit Take the t values in pairs. The ray enters P at the first time in each pair and exits from P at the second time of each pair

17 Exercises Draw an icosahedron by using the following drawing routine to use vertex arrays. Icosahedron approximate a sphere by using 20 polygons. After finish it, try to use recursive method to further divide each triangle to get more triangles to better approximate the sphere. #define x.525731112119133606 #define z.850650808352039932 void display (void) {static GLfloatv data[12][3] = { {-x,0.0,z},{x,0.0,z}, {-x,0.0,-z},{x,0.0,- z},{0.0,z,x},{0.0,z,-x},{0.0,-z,x}, {0.0,-z,-x},{z,x,0.0},{-z,x,0.0},{z,-x,0.0},{-z,-x,0.0} }; static GLuinttindices[20][3] = { {0,4,1},{0,9,4},{9,5,4},{4,5,8},{4,8,1},{8,10,1},{8,3,10},{5,3,8},{5,2,3},{2,7,3},{7,10,3},{7, 6,10},{7,11,6},{11,0,6},{0,1,6},{6,1,10},{9,0,11},{9,11,2},{9,2,5}, {7,2,11} };

18 Exercises Implement a 2D/3D Cyrus-Beck Algorithm for convex polygon or polyhedron by prompt user to input a ray and a sequence of bounding lines/bounding plane. Output the enter point and exit point.

19 Exercises for (i = 0; i < 20; i++) { glVertex3fv(&vdata[tindices[i][0]][0]); glVertex3fv(&vdata[tindices[i][1]][0]); glVertex3fv(&vdata[tindices[i][2]][0]); }


Download ppt "Ray Polygon Interception: Cyrus Beck Algorithm Mengxia Zhu Fall 2007."

Similar presentations


Ads by Google