collision detection & bounding boxes 數位內容學院 遊戲開發研究班第一期 3d 圖學...
TRANSCRIPT
Course Information
• Date: 5/19, 5/21, 5/26, 5/28 (2005)• Lecturer: Edward Yu-Te Shen 沈育德 • Course Website:
http://graphics.csie.ntu.edu.tw/~edwards/lecture.php
Schedule
• Artificial Lives: Fishes and Evolving Creatures (Saturday, May 21)
• Crowd Simulation & Script Languages (Thursday, May 26)
• Collision Detection and Bounding Boxes (Saturday, May 28)– OBB (oriented bounding box)
• We’ll have more math here– I-Collide
Collision Detection
• Finding coincident geometry – e.g. what polygons intersect in this
environment
• Detection by object– Don’t care about collisions among an object’s
polygons – Choice of “what is an object” somewhat
arbitrary
Applications
• Motion planning – Compute collision-free paths for automated tasks
• Virtual prototyping / simulation – Test functionality of mechanical assemblies
• Computer animation – Physically-based animations
• Virtual environments – Detect interactions of user with environment – Determine interactions among virtual objects
Triangle-Triangle Intersection
• Intersect if edge of one triangle intersects other triangle – 6 such tests produces complete tri-tri test – Faster methods possible
• see Moller, "A Fast Triangle-Triangle Intersection Test", Journal of Graphics Tools, 2(2), 1997.
• Edge-triangle intersection – Find intersection of line and plane – Check if intersection is within edge – Check if intersection is within triangle
Hierarchical Representations
• Two Common Types:– Bounding volume hierarchies – trees of spheres, ellipses, cub
es, axis-aligned bounding boxes (AABBs), oriented bounding boxes (OBBs), K-dop, SSV, etc.
– Spatial decomposition - BSP, K-d trees, octrees, MSP tree, R-trees, grids/cells, space-time bounds, etc.
• Do very well in “rejection tests”, when objects are far apart
• Performance may slow down, when the two objects are in close proximity and can have multiple contacts
BVH vs. Spatial Partitioning
BVH: SP:- Object centric - Space centric
- Spatial redundancy - Object redundancy
BVH vs. Spatial Partitioning
BVH: SP:- Object centric - Space centric
- Spatial redundancy - Object redundancy
BVH vs. Spatial Partitioning
BVH: SP:- Object centric - Space centric
- Spatial redundancy - Object redundancy
BVH vs. Spatial Partitioning
BVH: SP:- Object centric - Space centric
- Spatial redundancy - Object redundancy
Spatial Data Structures & Subdivision
• Many others……
Uniform Spatial Sub Quadtree/Octree kd-tree BSP-tree
Uniform Spatial Subdivision• Decompose the objects (the entire simulated environm
ent) into identical cells arranged in a fixed, regular grids (equal size boxes or voxels)
• To represent an object, only need to decide which cells are occupied. To perform collision detection, check if any cell is occupied by two object
• Storage: to represent an object at resolution of n voxels per dimension requires upto n3 cells
• Accuracy: solids can only be “approximated”
Octrees
• Quadtree is derived by subdividing a 2D-plane in both dimensions to form quadrants
• Octrees are a 3D-extension of quadtree
• Use divide-and-conquer
• Reduce storage requirements (in comparison to grids/voxels)
Bounding Volume Hierarchies
• Model Hierarchy: – each node has a simple volume that bounds a set
of triangles – children contain volumes that each bound a
different portion of the parent’s triangles – The leaves of the hierarchy usually contain
individual triangles
• A binary bounding volume hierarchy:
Bounding Volume Hierarchies
• Model Hierarchy: – each node has a simple volume that bounds a set
of triangles – children contain volumes that each bound a
different portion of the parent’s triangles – The leaves of the hierarchy usually contain
individual triangles
• A binary bounding volume hierarchy:
Type of Bounding Volumes• Spheres• Ellipsoids• Axis-Aligned Bounding Boxes (AABB)• Oriented Bounding Boxes (OBBs)• Convex Hulls• k-Discrete Orientation Polytopes (k-dop)• Spherical Shells • Swept-Sphere Volumes (SSVs)
– Point Swetp Spheres (PSS)– Line Swept Spheres (LSS)– Rectangle Swept Spheres (RSS)– Triangle Swept Spheres (TSS)
Collision Detection using BVH
1. Check for collision between two parent nodes (starting from the roots of two given trees)
2. If there is no interference between two parents, 3. Then stop and report “no collision”4. Else All children of one parent node are
checked against all children of the other node5. If there is a collision between the children6. Then If at leave nodes7. Then report “collision”8. Else go to Step 49. Else stop and report “no collision”
Evaluating Bounding Volume Hierarchies
Cost Function:
F = Nu x Cu + Nbv x Cbv + Np x Cp
F:total cost function for interference detection
Nu: no. of bounding volumes updated
Cu: cost of updating a bounding volume,
Nbv: no. of bounding volume pair overlap tests
Cbv: cost of overlap test between 2 BVs
Np: no. of primitive pairs tested for interference
Cp: cost of testing 2 primitives for interference
Designing Bounding Volume Hierarchies
The choice governed by these constraints:
– It should fit the original model as tightly as possible (to lower Nbv and Np)
– Testing two such volumes for overlap should be as fast as possible (to lower Cbv)
– It should require the BV updates as infrequently as possible (to lower Nu)
Observations
• Simple primitives (spheres, AABBs, etc.) do very well with respect to the second constraint. But they cannot fit some long skinny primitives tightly.
• More complex primitives (minimal ellipsoids, OBBs, etc.) provide tight fits, but checking for overlap between them is relatively expensive.
• Cost of BV updates needs to be considered.
Trade-off in Choosing BV’s
increasing complexity & tightness of fit
decreasing cost of (overlap tests + BV update)
AABB OBBSphere Convex Hull6-dop
Building Hierarchies
• Choices of Bounding Volumes– cost function & constraints
• Top-Down vs. Bottum-up– speed vs. fitting
• Depth vs. breadth– branching factors
• Splitting factors– where & how
Sphere-Trees
• A sphere-tree is a hierarchy of sets of spheres, used to approximate an object
• Advantages:– Simplicity in checking overlaps between two bounding sphere
s– Invariant to rotations and can apply the same transformation t
o the centers, if objects are rigid
• Shortcomings:– Not always the best approximation (esp bad for long, skinny o
bjects)– Lack of good methods on building sphere-trees
Methods for Building Sphere-Trees
• “Tile” the triangles and build the tree bottom-up
• Covering each vertex with a sphere and group them together
• Start with an octree and “tweak”
• Compute the medial axis and use it as a skeleton for multi-res sphere-covering
• Others……
Building an OBB Tree: Fitting
Covariance matrix ofpoint coordinates describesstatistical spread of cloud.
OBB is aligned with directions ofgreatest and least spread (which are guaranteed to be orthogonal).
Fitting OBBs
• Let the vertices of the i'th triangle be the points ai, bi, and ci, then the mean µ and covariance matrix C can be expressed in vector notation as:
where n is the number of triangles, and
Eigenvalue & Eigenvector
• We can extract n eigenvectors and the respective eigenvalues from a n x n covariance matrix
• The eigenvectors of C are the coordinates computed from C, each has a length n
• An eigenvector’s corresponding eigenvalue describes how sparse the points are in this direction (dimension)
To Understand The Arithmetic..
• Variance– In fact the same
• Standard Deviation– The larger, the more sparse
Covariance
• Standard deviation and variance (1 dimension)
• Now we have more
• How these dimensions effect each other?– i.e. how much the dimensions vary from the
mean with respect to each other
Covariance Matrix
• Always measures between 2 dimensions.
• For dimension (x , y , z) we could calculate cov(x, y), cov(y, z), and cov(x, z).
Notes on Eigenvectors• If you scale a vector by some amount, all you are
doing is making it longer, not changing it’s direction.
• All the eigenvectors of a matrix are perpendicular, no matter how many dimensions there are.
• Another word for perpendicular, is orthogonal. It means that:– Data can be expressed in terms of these perpendicular
eigenvectors, instead of the x, y axes.– None of these vectors can be expressed by linear
combinations of other 2 or more vectors
Building an OBB Tree: Summary
OBB Fitting algorithm:
• covariance-based
• use of convex hull
• not foiled by extreme distributions
• O(n log n) fitting time for single BV
• O(n log2 n) fitting time for entire tree
Tree Traversal
Disjoint bounding volumes:Disjoint bounding volumes:No possible collisionNo possible collision
Overlapping bounding volumes:• split one box into children• test children against other box
Tree Traversal
Separating Axis Theorem
L is a separating axis for OBBs A & B, since A & B become disjoint intervals under projection onto L
Separating Axis Theorem
Two polytopes A and B are disjoint iff there
exists a separating axis which is:
perpendicular to a face from either
or
perpedicular to an edge from each
Implications of Theorem
Given two generic polytopes, each with E edges and F faces, number of candidate axes to test is:
2F + E2
OBBs have only E = 3 distinct edge directions, and only F = 3 distinct face normals. OBBs need at most 15 axis tests.
Because edge directions and normals each form orthogonal frames, the axis tests are rather simple.
OBB Overlap Test: Axis Test Details
Box centers project to interval midpoints, so
midpoint separation is length of vector T’s image.
A
B
nTAT
BT
s
nTT BAs
OBB Overlap Test: Axis Test Details
• Half-length of interval is sum of box axis images.
n
B
rB
nRnRnR BBBB bbbr 332211
OBB Overlap Test
• Strengths of this overlap test:– 89 to 252 arithmetic operations per box overlap
test– Simple guard against arithmetic error– No special cases for parallel/coincident faces,
edges, or vertices– No special cases for degenerate boxes– No conditioning problems– Good candidate for micro-coding
OBB Overlap Tests: Comparison
Benchmarks performed on SGI Max Impact,
250 MHz MIPS R4400 CPU, MIPS R4000 FPU
Test Method Speed(us)
Separating Axis 6.26GJK 66.30LP 217.00
Parallel Close Proximity
Q: How does the number of BV tests increase as the gap size decreases?
Two models are in parallel close proximity when every point on each model is a given fixed distance (e) from the other model.
I-COLLIDE
• An exact and interactive collision detection system
• A two-level approach– Pruning multiple object pairs using bounding
boxes– Performing exact collision detection between
selected pairs of polyhedral models
I-COLLIDE
• Main contribution– Temporal and geometric coherence
• To speed up both pruning and the exact collision detection
– The underlying assumption• Time steps are small so that the objects do not
travel large distances between frames
Pruning Multi-body Pairs
• N moving objects + M static objects
• Objective– to reduce the number of pairs of objects that are actually
compared, to give O(N+M)• Use coherence
– By sorting objects in 3-space– Assumes each object is surrounded by a 3-D bounding volume
(AABB)• Use Dimension Reduction to sort the objects in 3-space
3-D Bounding Volumes(AABB)
• Types– Fixed-Size Bounding Cubes
• Recalculating fixed size bounding cubes add less overhead, as their size remains constant.
– Dynamically-Resized Rectangular bounding bounding boxes.
• Dynamically resized bounding boxes are the “tightest” axis-aligned box containing the object at a particular orientation.
• More overhead due to recomputation of min, max x,y,z values
R
3-D Bounding volumes
• Dynamic resizing works well with oblong objects, which results in fewer overlaps.
• In walkthrough environments, with few objects moving, the savings gained by fewer pairwise comparisons outweighs the cost of recomputing dynamic bounding box volumes.
Dimension Reduction
• If two bodies collide in 3-D space, their orthogonal projections onto the xy, yz, and xy planes, and x, y, and z axes must overlap.
• Two AABB intersect, if and only if their projections onto all three axis intersect.– This is why the bounding boxes are axis aligned.
• 1-D Sweep and Prune (projection onto x, y, z axes)
• 2D Intersection tests (projection onto xy, yz, xz planes)
1-D Sweep and Prune• Bounding Volumes projected onto x, y, and z
axes• Have one sorted list for each dimension• Maintain Boolean flag which only changes if
swaps are made on sorted lists.– An upper-triangular O(n2) matrix
1-D Sweep and Prune
• If flags are true for all 3 dimensions,– we pass this pair on to exact collision
detection.
• Due to temporal coherence, individual lists are likely almost sorted already.
• Insertion sort works well where large numbers of objects move locally.– O(n+s), where s is the number of pairwise
overlaps
2D Intersection Tests
• Bounding Volumes projected onto xy, yz, and zx planes– Three 2D rectangles instead of 1D intervals
• Maintain the interval tree for performing 2D range queries [F.P. Preparata and M. I. Shamos. Computational Geometry, Springer-Verlag]
Object Sorting
• Sort objects in space to determine which object pairs overlap.
• Test only these pairs for collisions– (methods for determining overlaps and testing
collisions are often independent)
Dimension Reduction
• Works better than space partitioning approaches where it is difficult to choose good partition sizes.
V-Collide
• Collision detection for large polygonal environments– Combines I-Collide pruning algorithm with
RAPID intersection test– Provides efficient collision detection for n
arbitrary polygonal models– Improves space efficiency over I-Collide
Implementation
• Available at: http://www.cs.unc.edu/~geom/OBB
• Part of V-COLLIDE: http://www.cs.unc.edu/~geom/V_COLLIDE
• Thousands of users have ftp’ed the code
• Used for virtual prototyping, dynamic simulation, robotics & computer animation