Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Tracing Polyhedra ©Anthony Steed

Similar presentations


Presentation on theme: "Ray Tracing Polyhedra ©Anthony Steed"— Presentation transcript:

1 Ray Tracing Polyhedra ©Anthony Steed 1999-2003
Covers chapter 8.2 of Computer Graphics and Virtual Environments (Slater, Steed and Chrysanthou) . See ©Anthony Steed

2 Overview Barycentric coordinates Ray-Polygon Intersection Test
Affine Transformations

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

4 A Barycentric Combination is
a weighted sum of points, where weight sum to 1. Let p1,p2,…,pn be points Let a1,a2,…,an be weights

5 Implications If p1,p2,…,pn are co-planar points then p as defined will be inside the polygon defined by the points Plenty of diagrams

6 Outline of Polygon Ray Tracing
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 Does the ray intersect the plane?
Ray eq. is p0 + t.d Plane eq. is n.(x,y,z) = k Then test is n.d !=0

8 Where does it intersect?
Substitute line equation into plane equation Solve for t Find pi

9 Is this point inside the polygon?
If it is then it can be represented in barycentric co-ordinates. 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 Winding number test Sum the angles subtended by the vertices. If sum is zero, then outside. If sum is +/-2, inside. With non convex shapes, can get +/-4, +-6, etc… p2 1 p1 n-1 pn-1

11 Infinite Ray Test 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 For convex polygons you can just count the number of crossings, ignoring the sign If total is even then point is outside, otherwise inside -1 +1 We return to hit testing in a later lecture. For now consider these rules thus: For the non-zero rule, every point inside the external border is “inside” the polygon. That is, if you have to cross any line to get “out” of the polygon, you are inside. For the odd-even rule, if a point is in two (or an even number) of different “parts” of the shape it is outside. Effectively when filling the shape, every time we fill a point, we toggle it on or off.

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

13 Transformations Revisited
Homogenous transform as described is affine Preserves barycentric co-ordinates f is affine iff n ( ) å ( ) f p = a f p i i i = 1 n å p = a p i i i = 1 n å a = 1 i i = 1

14 To Show Transformation is Affine
Unit vectors e1=(1 0 0), e2=(0 1 0), e3=(0 0 1) and e4=(0 0 0) p=(x1 x2 x3) Let x4=1-x1-x2-x3 Thus

15 ... But for unit vectors, mapping is easy to derive

16 So combine those two

17 ... But we know x4=1-x1-x2-x3

18 ... Expand that, remembering what ei is
But this is the matrix transformation

19 Why? If a rotation, scale, translation are affine then barycentricity is preserved If barycentricity is preserved then polygons are still flat after transformation

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


Download ppt "Ray Tracing Polyhedra ©Anthony Steed"

Similar presentations


Ads by Google