Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Ray Tracing Polyhedra ©Anthony Steed 1999-2005.

Similar presentations


Presentation on theme: "1 Ray Tracing Polyhedra ©Anthony Steed 1999-2005."— Presentation transcript:

1 1 Ray Tracing Polyhedra ©Anthony Steed 1999-2005

2 2 Overview n Barycentric coordinates n Ray-Polygon Intersection Test n Affine Transformations

3 3 Line Equation n Recall that given p 1 and p 2 in 3D space, the straight line that passes between is: for any real number t n This is a simple example of a barycentric combination

4 4 A Barycentric Combination is n a weighted sum of points, where weight sum to 1. Let p 1,p 2,…,p n be points Let a 1,a 2,…,a n be weights

5 5 Implications n If p 1,p 2,…,p n are co-planar points then p as defined will be inside the polygon defined by the points n Proof of this is out of scope, but a few diagrams should convince you of the outline of a proof …

6 6 Ray Tracing a Polygon n Three steps Does the ray intersect the plane of the polygon? –i.e. is the ray not orthogonal to the plane normal Intersect ray with plane Test whether intersection point lies within polygon on the plane

7 7 Does the ray intersect the plane? n Ray eq. is p 0 + t.d n Plane eq. is n.(x,y,z) = k n Then test is n.d !=0

8 8 Where does it intersect? n Substitute line equation into plane equation n Solve for t n Find p i

9 9 Is this point inside the polygon? n If it is then it can be represented in barycentric co-ordinates n There are potentially several barycentric combinations n Many tests are possible Winding number (can be done in 3D) Infinite ray test (done in 2D) Half-space test (done in 2D for convex poylgons)

10 10 Winding number test n Sum the angles subtended by the vertices. If sum is zero, then outside. If sum is +/-2 , inside. n With non convex shapes, can get +/- 4 , +-6 , etc… 1 n-1 p1p1 p2p2 p n-1

11 11 Infinite Ray Test n Draw a line from the test point to the outside Count +1 if you cross an edge in an anti-clockwise sense Count -1 if you cross and edge in a clockwise sense n For convex polygons you can just count the number of crossings, ignoring the sign n If total is even then point is outside, otherwise inside +1

12 12 Half-Space Test (Convex Polygons) n A point p is inside a polygon if it is in the negative half-space of all the line segments

13 13 Note n That the winding angle and half-space tests only tell you if the point is inside the polygon, they do not get you a barycentric combination n With some minor extensions, its easy to show that the infinite ray test finds a barycentric combination.

14 14 Transforming Polygons n Although its sort of “obvious” that transformations of object preserve flatness and shape, we need to convince ourselves of something specific: that barycentric coordinates are preserved under affine transformations n If they weren’t it would be extremely hard to shade and texture polygons later on in the course n If a rotation, scale, translation are affine then barycentricity is preserved n If barycentricity is preserved then polygons are still “flat” after transformation

15 15 Transformations Revisited n Homogenous transform as described is affine n Preserves barycentric co-ordinates n f is affine iff

16 16 To Show Transformation is Affine n Unit vectors e 1 =(1 0 0), e 2 =(0 1 0), e 3 =(0 0 1) and e 4 =(0 0 0) n p=(x 1 x 2 x 3 ) n Let x 4 =1-x 1 -x 2 -x 3 n Thus

17 17... n But for unit vectors, mapping is easy to derive

18 18 … n So combine those two

19 19... n But we know x 4 =1-x 1 -x 2 -x 3

20 20... n Expand that, remembering what e i is n But this is the matrix transformation

21 21 Recap n Lines and polygons (and volumes) can be determined in terms of barycentric coordinates n We have shown that homogenous transformations are, by definition, affine n This polygons remain “flat” n Thus we now can use arbitrary transformations on polyhedra


Download ppt "1 Ray Tracing Polyhedra ©Anthony Steed 1999-2005."

Similar presentations


Ads by Google