Download presentation
Presentation is loading. Please wait.
1
Advanced Computer Graphics Spring 2009
K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology
2
Today’s Topics Intersection Test Methods Ray/object Object/object
3
Introduction Intersection testing is often used in computer graphics.
Click the mouse on an object. (Object picking) Determine whether two objects collide. Make sure we maintain a constant height for our viewer as we navigate a building.
4
Definitions and Tools A ray r(t) is defined by an origin point o and a direction unit vector, d. r(t) = o + td. The scalar t is a variable that is used to generate different points on the ray. t < 0 : points that lie behind the ray origin (not part of the ray). t > 0 : points that lie in front of the origin. In practice we often store a current distance l, which is the maximum distance we want to search along the ray.
5
Definitions and Tools Implicit Surfaces Explicit Surfaces
A surface defined by an implicit function f(p) = f(px,py,pz) = 0. Explicit Surfaces A surface defined by a vector function f and some parameters rather than a point on the surface f(u,v) = (fx(u,v),fy(u,v),fz(u,v))
6
Definitions and Tools Three Bounding Volumes
AABB: Axis-Aligned Bounding Box OBB: Oriented Bounding Box k-DOP: k – Discrete Oriented Polytope
7
Definitions and Tools AABB
An Axis-aligned Bounding Box (also called rectangular box), is a box whose faces have normals that coincide with the standard basis axes.
8
Definitions and Tools OBB
An Oriented Bounding Box is a box whose faces have normals that are all pairwise orthogonal. It is an AABB that is arbitrarily rotated.
9
Definitions and Tools K-DOP
A k-Discrete Oriented Polytope is defined by k/2 (where k is even) normalized normals (orientations), ni, 1 ≤ i ≤ k/2 and with each ni, two associated scalar values dimin and dimax where dimin < dimax. Each triple(ni,dimin,dimax) describes a slab, Si, which is the volume between the two planes, пimin : niᆞx + dimin = 0 and пimax : niᆞx + dimax = 0 and where the intersection of all slabs, ∩1≤l ≤k/2 Sl is the actual k-DOP volume.
10
Definitions and Tools K-DOP An 8-DOP in two dimensions
11
Definitions and Tools Separating Axis Theorem (SAT)
For any two arbitrary, convex, disjoint polyhedra, A and B, there exists a separating axis where the projections of the polyhedra, which form intervals on the axis, are also disjoint.
12
Definitions and Tools Separating Axis Theorem (SAT)
If A and B are disjoint, then they can be separated by an axis that is orthogonal to either a face of A a face of B An edge from each polyhedron
13
Bounding Volume Creation
Given a collection of objects, finding a tight fitting bounding volume is important to minimizing intersection costs. The chance that an arbitrary ray will hit any convex object is proportional to that objects’ surface area. Minimizing this area increases the efficiency of any intersection algorithm as a rejection is never slower to compute than an intersection. It is often better to minimize the volume of BV for collision detection algorithms.
14
AABB and k-DOP Creation
The simplest bounding volumes to create is an AABB. Take the minimum and maximum extents of the set of polygon vertices along each axis and the AABB is formed.
15
AABB and k-DOP Creation
Project the vertices onto each normal, ni, of the k-DOP. Extreme values (min,max) of these projections are stored in dimin and dimax. These two values define the tightest slab for that direction. Together, all such values define a minimal k-DOP.
16
Sphere Creation Form an AABB for the polygon set and then use the center and the diagonal of this box to form the sphere. This sometimes gives a poor fit, and the fit can often be improved by another quick pass. Starting with the center of the AABB as the center of the sphere BV. Go through all vertices once again and find the one that is farthest from this center. This is then the new radius.
17
Sphere Creation Ritter’s algorithm: a near optimal bounding sphere.
Find the vertex that is at the minimum and the vertex at the maximum along each of the x, y and z axes. For these three pairs of vertices, find the pair with the largest distance between them. Use this pair to form a sphere with its center at the midpoint between them and a radius equal to the distance to them. Go through all the other vertices and check its distance d to the center of the sphere. If the vertex is outside the sphere’s radius r, move the sphere’s center toward the vertex by (d-r)/2, set the radius to (d+r)/2 and continue. This step has the effect of enclosing the vertex and the existing sphere in a new sphere. After this second time through the list, the bounding sphere is guaranteed to enclose all vertices.
18
Sphere Creation Welzl’s algorithm
Expected to be linear for a randomized list of vertices. The idea is to find a supporting set of points defining a sphere. When a vertex is found to be outside the current sphere, its location is added to the supporting set. The new sphere is computed and the entire list is run through again. This process repeats until the sphere contains all vertices. This algorithm guarantees that an optimal bounding sphere is found.
19
OBB Creation Gottschalk’s method
A tight-fitting OBB enclosing an object can be found by computing an orientation from the triangles of the convex hull. Formulae for computing a good fit OBB using a statistical method The convex hull of an object must be computed. O(nlog(n)). Quickhull algorithm. This gives us n triangles defined as Δpkqkrk, (vertices of triangle k), the area of triangle k as ak, and the total area of the convex hull as aH, the sum of ak.
20
OBB Creation Gottschalk’s method
The convex hull of an object must be computed. O(nlog(n)). The centroid of the whole convex hull, mH.: the weighted mean of the triangle centroids. Construct a 3 by 3 covariance matrix C.
21
OBB Creation Gottschalk’s method
Compute the eigenvalues of C, which are the direction vectors for a good-fit box, au, av, and aw. Find the center and the half-lengths of the OBB. This is done by projecting the points of the convex hull onto the direction vectors and finding the minimum and maximum along each direction. This will determine the size and position of the box and fully specify the OBB according to its definition.
22
OBB Creation Eberly’s method
A method for computing a minimum-volume OBB using a minimization technique.- Iterative algorithm. The convex hull need not be computed. For a box with the axis au, av and aw, the points are projected onto these axes. The min, kumin and kumax along au are found. Then, kvmin, kvmax, kwmin, and kwmax are computed similarly. The center of this box is then
23
OBB Creation Eberly’s method
The set of possible directions of the box are sampled and the axes are used whose box is smallest as a starting point for the numeric minimizer. Then Powell’s direction set method is used to find the minimum volume box.
24
Rules of Thumb For faster, more robust and more exact intersection tests, Perform computations and comparisons that might trivially reject or accept various types of intersections to obtain an early escape from further computations. If possible, exploit the results from previous tests. If more than one rejection or acceptance test is used, then try changing their internal order, since a more efficient test may result. Do not assume that what appears to be a minor change will have no effect. Postpone expensive calculations until they are truly needed. The intersection problem can often be simplified considerably by reducing the dimension of the problem.
25
Rules of Thumb For faster, more robust and more exact intersection tests, If a single ray or object is being compared to many other objects at a time, look for precalculations that can be done just once before the testing begins. Whenever an intersection test is expensive, it is often good to start with a sphere around the object to give a first level of quick rejection. Make it a habit always to do timing comparisons on your computer, and use real data and testing situations for the timings. Try to make your code robust. This means it should work for all special cases and that it will be insensitive to as many floating point precision errors as possible. Be aware of any limitations it may have.
26
Ray/Sphere Intersection
Mathematical solution A sphere can be defined by a center point, c, and a radius r. f(p) = ||p-c|| - r = 0, p is any point on the sphere’s surface. Given a ray r(t), we can find the intersections as follows: f(r(t)) = ||r(t) –c|| - r = 0.
27
Ray/Sphere Intersection
Mathematical solution The equation is of quadratic form t2+2tb+c=0, b=dᆞ(o-c), c = (o-c)ᆞ(o-c) - r2.
28
Ray/Sphere Intersection
For the other quadrics, e.g., the cylinder, ellipsoid, cone and hyperboloid, the mathematical solutions to their intersection problems are almost as straightforward as for the sphere. Sometimes, it is necessary to bound a surface (cylinder).
29
Ray/Sphere Intersection
Optimized Solution Intersections behind the ray origin are not needed. Compute a vector l = c – o, the vector from the ray origin to the center of the sphere. The squared length of the vector : l2 = lᆞl. If l2 < r2, the ray origin is inside the sphere. This guarantees that the ray hits the sphere.
30
Ray/Sphere Intersection
Optimized Solution Compute the projection of l onto the ray direction d: s = lᆞd. If s < 0 and the ray origin is outside the sphere, then the sphere is behind the ray origin and we can reject the intersection. Otherwise, the squared distance from the sphere center to the projection is computed using the Pythagorean theorem: m2 = l2-s2. If m2 > r2 the ray will definitely miss the sphere and the rest of the calculations can safely be omitted. If the sphere and ray pass this last test, then the ray is guaranteed to hit the sphere.
31
Ray/Sphere Intersection
Optimized Solution Computation of the real intersection points Calculate the squared distance q2 = r2 – m2. Since m2 <= r2, q = q1/2 The distances to the intersections are t = s ± q If we are interested in only the first, positive intersection point, then t1 = s – q for the case where the ray origin is outside the sphere. t2 = s + q when the ray origin is inside.
32
Ray/Sphere Intersection
Optimized Solution Computation of the real intersection points
33
Ray/Box Intersection Three methods for determining whether a ray intersects a box are introduced. Both AABBs and OBBs Faster than the first one but can deal with only the simpler AABB. Based on the separating axis theorem and handles only line segments versus AABBs.
34
Ray/Box Intersection (Slabs Method)
A slab is the volume between the two parallel planes. A box is considered to be a set of three slabs in 3D (2 in 2D)
35
Ray/Box Intersection (Slabs Method)
For each slab, there is a minimum and a maximum t-value and these are called tmini and tmaxi i = u, v, w. The next step is to compute the variables as follows tmin = max(tminu,tminv,tminw) tmax = min(tmaxu,tmaxv,tmaxw) The clever test: If tmin ≤ tmax, then the ray intersects the box. Otherwise it misses. A generalized of the slabs method can be used to compute the intersection of a ray with a k-DOP, frustum, or any convex polyhedron.
36
Ray/Box Intersection (Woo’s Method)
Some smart optimizations for finding the intersection between a ray and an AABB. Given a ray and an AABB, denoted B, the idea is to identify three candidate planes out of the six planes composing the AABB. For each pair of parallel planes, the back-facing plane can be omitted from further consideration. After finding these three planes, we compute the intersection distances (t-values) between the ray and the planes. The largest of these distances corresponds to a potential hit.
37
Ray/Box Intersection (Woo’s Method)
If a potential hit is found, the actual intersection point is computed. If it is located on the corresponding face of B, then it is a real hit. d o
38
Ray/Box Intersection (Line Segment/Box Overlap Test)
The separating axis theorem can be used to determine whether a line segment overlaps an AABB. The line segment has finite length in contrast to a ray. The line segment is defined by a center c and a half vector w. Both the AABB, denoted B, and the line segment have been translated so the AABB’s origin is (0,0,0). The size of the box is (2hx,2hy,2hz), h is the half vector of the box.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.