Download presentation
Presentation is loading. Please wait.
Published byAmber Curtis Modified over 9 years ago
1
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology
2
2 Ray/Box Intersection (Line Segment/Box Overlap Test) One should first test against an axis that is orthogonal to a face of both objects to be tested.
3
3 Ray/Box Intersection (Line Segment/Box Overlap Test) Since the line segment does not have a face, it does not generate any test. The box generates three axes to test: (1,0,0), (0,1,0) and (0,0,1). Finally, the axes formed from the cross product between line segment direction and the box axes should be tested. The test for the axis (1,0,0) is as follows: |c x | > |w x | + h x. If the test is true then the line segment and the box do not overlap.
4
4 Ray/Box Intersection (Line Segment/Box Overlap Test) The cross product axis a = w ⅹ (1,0,0) =(0,w z,-w y ) is tested as follows: The extent of the box projected onto a is h y |w z | + h z |w y |. Next we need to find the projected length of the line segment, and the projection of the line segment center. The projection of the line segment direction w onto a is zero, since w ⅹ (w ᆞ (1,0,0))=0. Thus the test becomes |c y w z -c z w y | > h y |w z | + h z |w y | If the test is true, then there is no overlap.
5
5 Ray/Triangle Intersection In real-time graphics libraries, triangle geometry is usually stored as a set of vertices with associated normals. Each triangle is defined by three vertices. The normal of the plane in which the triangle lies is often not stored. It must be computed if needed. Significant memory savings are possible. We can reduce the problem to two dimensions by projecting the intersection point and the triangle vertices on the axis-aligned plane where the area of the triangle is maximized. We need only decide whether the 2D point is inside the 2D triangle.
6
6 Ray/Triangle Intersection The ray r(t) = o + td. A Triangle is defined by three vertices v 1, v 2 and v 3, i.e. Δv 1 v 2 v 3.
7
7 Ray/Triangle Intersection (Intersection Algorithm) A point t(u,v) on a triangle is given by the explicit formular t(u,v) = (1-u-v)v 0 +uv 1 +vv 2, (u,v) are the barycentric coordinates, u,v≥0, u+v≤1. u and v are the amounts by which to weight each vertex’s contribution to a particular location, with w=(1-u-v) being the third weight.
8
8 Ray/Triangle Intersection (Intersection Algorithm) Intersection between the ray, r(t) and the triangle, t(u,v) is equivalent to r(t)=t(u,v). o+td = (1-u-v)v 0 + uv 1 + vv 2. We construct the linear system of equations whose roots are the barycentric coordinates (u,v) and the distance t from the ray origin to the intersection point.
9
9 Ray/Triangle Intersection (Intersection Algorithm) Intersection between the ray, r(t) and the triangle, t(u,v) is equivalent to r(t)=t(u,v).
10
10 Ray/Triangle Intersection (Intersection Algorithm) Solution (e 1 =v 1 -v 0,e 2 =v 2 -v 0 and s=o-v 0 )
11
11 Ray/Polygon Intersection Triangles are the most common rendering primitive. But having a routine that computes the intersection between a ray and a polygon is useful. A polygon of n vertices is defined by an ordered vertex list {v 0,v 1,v 2,…,v n-1 } Vertex v i forms an edge with v i+1. The polygon is closed by the edge from v n-1 to v 0. The plane of the polygon is denoted π p : n p ·x + d p = 0.
12
12 Ray/Polygon Intersection We first compute the intersection between the ray and π p. Replace x by the ray. If |n p ·d|< ε, ε is a very small number, the ray is considered parallel to the polygon plane. There is no intersection between them. Otherwise, the intersection point, p, of the ray and the polygon plane is computed. p=o+td.
13
13 Ray/Polygon Intersection Thereafter, the problem of deciding whether p is inside the polygon is reduced from three to two dimensions. This is done by projecting all vertices and p to one of the xy, xz, yz planes where the area of the projected polygon is maximized. Example. Given a normal (0.6,-0.692,0.4), the y component has the largest magnitude, so all y coordinates are ignored. This component information could be precomputed once and stored within the polygon for efficiency.
14
14 Ray/Polygon Intersection A two-dimensional bounding box for the polygon is also sometimes profitable. First compute the intersection with the polygon plane. Project to two dimensions Test against the two-dimensional bounding box. If the point is outside the box, then reject and return. Otherwise, continue with the full polygon test. Better approach than using a 3D bounding box.
15
15 Ray/Polygon Intersection The question left is whether the two-dimensional ray/plane intersection point p is contained in the two- dimensional polygon. The Crossings Test The crossings test is based on the Jordan Curve Theorem. A point is inside if a ray from this point in an arbitrary direction crosses an odd number of polygon edges. Also known as the parity or the even-odd test. This condition does not mean that all areas enclosed by the polygon are considered insided.
16
16 Ray/Polygon Intersection The crossings algorithm is the fastest test that does not use preprocessing. It works as follows: Shoot a ray from the projection of the point p along the positive x-axis. Compute the number of crossings between the polygon edges and the ray. An odd number of crossings indicates that the point is inside the polygon.
17
17 Ray/Polygon Intersection The test point p can also be thought of as being at the origin and the edges may be tested against the positive x-axis. If the y-coordinates of a polygon edge have the same sign, then that edge cannot cross the x-axis. Otherwise, it can, and then the x-coordinates are checked. If both are positive, then the number of crossings is incremented. If they differ in sign, the x-coordinate of the intersection between the edge and the x-axis must be computed and if it is positive, the number of crossings is again incremented.
18
18 Ray/Polygon Intersection Problems might occur when the test ray intersects a vertex, since two crossings might be detected. These problems are solved by setting the vertex infinitesimally above the ray. It is done by interpreting the vertices with y >=0 as lying above the x-axis.
19
19 Ray/Polygon Intersection The advantages of the crossings test It is relatively fast and robust. It requires no additional information or preprocessing for the polygon. The disadvantage of this method It does not yield anything beyond the indication of whether a point is inside or outside the polygon.
20
20 Plane/Box Intersection Detection One way to determine whether a box intersects a plane is to insert all the vertices of the box into the plane equation. If both a positive and a negative result (or a zero) is obtained, then vertices are located on both sides of (or on) the plane. -> An intersection has been detected. This is somehow a brute force method. The idea behind faster ways is that only two points need to be inserted into the plane equation. These points are the ones that form a diagonal of the box, where the diagonal passes through the center of the box and is most aligned to the normal of the plane than are the other pairs of points that form diagonals.
21
21 Plane/Box Intersection Detection (AABB) Given an AABB, B, defined by b min and b max, four different diagonals can be constructed. All these pass through the center of B and have endpoints at the vertices of B. For this AABB/plane intersection test, first find out which of the box diagonals is most aligned with the plane normal, n. After such a diagonal is found, its two AABB vertices, called v min and v max, are inserted into the plane equation. This equation tests which side of the plane each endpoint is on. If the signs of the results differ, or at least one of them is zero, then B intersects the plane.
22
22 Plane/Box Intersection Detection (AABB)
23
23 Plane/Box Intersection Detection (OBB) With a small change, the test for AABB can be used to test a plane against an OBB. The trick lies in knowing how to identify the two points, v min and v max. When this has been done, the same test as for AABBs can be used. To identify such points, we transform the normal of the plane so that it lies in the coordinate system of the OBB.
24
24 Plane/Box Intersection Detection (OBB) We use the transformed normal n’ to find the points v min and v max n’ = (b u ᆞ n, b v ᆞ n, b w ᆞ n) T Another way to test an OBB against a plane is to project the axes of the OBB onto the normal of the plane. If the absolute value of the distance from the center of the OBB to the plane is larger than r, then the plane and the OBB do not intersect. Otherwise, they do.
25
25 Triangle/Triangle Intersection Graphics hardware uses the triangle as its most important drawing primitive, it is natural to perform collision detection tests on this kind of data. The deepest levels of a collision detection algorithm typically have a routine that determines whether or not two triangles intersect. More often than not, we are concerned only about whether they intersect at all, not interested in an exact intersection.
26
26 Triangle/Triangle Intersection The problem is: Given two triangles, T 1 =Δu 0 u 1 u 2 and T 2 = Δv 0 v 1 v 2, determine whether or not they intersect. Two methods are explained. The interval overlap method The method in the ERIT package.
27
27 Triangle/Triangle Intersection (Interval Overlap Method) First, the plane equation п 2 : n 2 ᆞ x + d 2 =0 is computed. n 2 =(v 1 -v 0 ) ⅹ (v 2 -v 0 ), d 2 = -n 2 ᆞ v 0 Then, the signed distances from the vertices of T 1 to п 2 are computed by simply inserting the vertices into the plane equation. d ui = n 2 ᆞ u i + d 2, i=0,1,2 If all d ui ≠0, i=0,1, and 2, and all have the same sign, the T 1 lies on one side of п 2 and the overlap is rejected. The same test is done for T 2 and п 1. These two early rejection tests allow us to avoid many computations for some triangle pairs.
28
28 Triangle/Triangle Intersection (Interval Overlap Method) If all d ui =0, for i=0,1, and 2, then the triangles are co- planar. If not, the intersection of п 1 and п 2 is a line, l = o + td, where d = n 1 ⅹ n 2 is the direction of the line and o is some point on it. These intersections form intervals on l, and if these intervals overlap the triangles overlap as well.
29
29 Triangle/Triangle Intersection (Interval Overlap Method) If all d ui =0, for i=0,1, and 2, then the triangles are co- planar. If not, the intersection of п 1 and п 2 is a line, l = o + td, where d = n 1 ⅹ n 2 is the direction of the line and o is some point on it. These intersections form intervals on l, and if these intervals overlap, the triangles overlap as well.
30
30 Triangle/Triangle Intersection (Interval Overlap Method) To compute a scalar interval (on l) that represents the intersection between T 1 and l. Ex. The triangle vertices u 0 and u 2 lie on the same side of п 2 and that u 1 lies on the other side. To find scalar values that represent the intersection between the edges u 0 u 1 and u 1 u 2 and l, the vertices are first projected onto l: p ui = d ᆞ (u i -o)
31
31 Triangle/Triangle Intersection (Interval Overlap Method)
32
32 Triangle/Triangle Intersection (Interval Overlap Method) To compute a scalar interval (on l) that represents the intersection between T 1 and l. Next we want to use the intersection point, called b, between the line l = o + td and the edge u 0 u 1. We call the t-value at the intersection point t 1. If we let k i denote the projection of u i onto п 2, we see that the triangles Δu 0 bk 0 and Δu 1 bk 1 are similar. Using this, t 1 can be computed as follows:
33
33 Triangle/Triangle Intersection (Interval Overlap Method) Similar calculations are done to compute t 2, which represents the intersection between the line l and the edge u 1 u 2. Together, t 1 and t 2 represent an interval on the line l where the triangle T 1 intersects l. Using similar techniques, an interval can be computed for the other triangle, T 2, as well. If these intervals overlap, the triangles intersect.
34
34 Triangle/Triangle Intersection (Interval Overlap Method) If the triangles are co-planar, they are projected onto the axis-aligned plane where the area of the triangles are maximized. Then, a simple two-dimensional triangle-triangle overlap test is performed. First, test all closed edges of T 1 for intersection with the closed edges of T 2. If any intersection is found, then the triangles intersect. Otherwise, we must test whether T 1 is totally contained in T 2 or vice versa. This can be done by performing a point-in-triangle test for one vertex of T 1 against T 2 and vice versa.
35
35 Triangle/Triangle Intersection (Interval Overlap Method) Optimizations Since the interval can be translated without altering the result of the interval overlap test, the previous equation p ui = d ᆞ (u i -o) can be simplified into p ui = d ᆞ u i,i = 0,1,2. o does not need to be computed. We can also scale the t-values without changing the result of the overlap test and therefore the divisions can be avoided by scaling all the t-values with appropriate factors. Also, the result of the overlap test does not change if we project l onto the coordinate axis with which it is most closely aligned. Therefore we have
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.