Presentation is loading. Please wait.

Presentation is loading. Please wait.

Collision Detection & Bounding Boxes 數位內容學院 遊戲開發研究班第一期 3D 圖學 沈育德 Edward Shen May 28, 2005.

Similar presentations


Presentation on theme: "Collision Detection & Bounding Boxes 數位內容學院 遊戲開發研究班第一期 3D 圖學 沈育德 Edward Shen May 28, 2005."— Presentation transcript:

1 Collision Detection & Bounding Boxes 數位內容學院 遊戲開發研究班第一期 3D 圖學 沈育德 Edward Shen May 28, 2005

2 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 http://graphics.csie.ntu.edu.tw/~edwards/lecture.php

3 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

4 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

5 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

6 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

7 Hierarchical Representations Two Common Types: –Bounding volume hierarchies – trees of spheres, ellipses, cubes, 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

8 BVH vs. Spatial Partitioning BVH: SP: - Object centric - Space centric - Spatial redundancy - Object redundancy

9 BVH vs. Spatial Partitioning BVH: SP: - Object centric - Space centric - Spatial redundancy - Object redundancy

10 BVH vs. Spatial Partitioning BVH: SP: - Object centric - Space centric - Spatial redundancy - Object redundancy

11 BVH vs. Spatial Partitioning BVH: SP: - Object centric - Space centric - Spatial redundancy - Object redundancy

12 Spatial Data Structures & Subdivision Many others…… Uniform Spatial Sub Quadtree/Octree kd-tree BSP-tree

13 Uniform Spatial Subdivision Decompose the objects (the entire simulated environment) 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 n 3 cells Accuracy: solids can only be “approximated”

14 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)

15 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:

16 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:

17 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)

18 BVH-Based Collision Detection

19 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 node 5. If there is a collision between the children 6. Then If at leave nodes 7. Then report “collision” 8. Else go to Step 4 9.Else stop and report “no collision”

20 Evaluating Bounding Volume Hierarchies Cost Function: F = N u x C u + N bv x C bv + N p x C p F:total cost function for interference detection N u : no. of bounding volumes updated C u :cost of updating a bounding volume, N bv :no. of bounding volume pair overlap tests C bv :cost of overlap test between 2 BVs N p : no. of primitive pairs tested for interference C p : cost of testing 2 primitives for interference

21 Designing Bounding Volume Hierarchies The choice governed by these constraints: –It should fit the original model as tightly as possible (to lower N bv and N p ) –Testing two such volumes for overlap should be as fast as possible (to lower C bv ) –It should require the BV updates as infrequently as possible (to lower N u )

22 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.

23 Trade-off in Choosing BV ’ s increasing complexity & tightness of fit decreasing cost of (overlap tests + BV update) AABB OBB Sphere Convex Hull 6-dop

24 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

25 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 spheres –Invariant to rotations and can apply the same transformation to the centers, if objects are rigid Shortcomings: –Not always the best approximation (esp bad for long, skinny objects) –Lack of good methods on building sphere-trees

26 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……

27 Building an OBBTree Recursive top-down construction: partition and refit

28 Given some polygons, consider their vertices... Building an OBB Tree

29 … and an arbitrary line Building an OBB Tree

30 Project onto the line Consider variance of distribution on the line Building an OBB Tree

31 Different line, different variance Building an OBB Tree

32 Maximum Variance Building an OBB Tree

33 Minimal Variance Building an OBB Tree

34 Given by eigenvectors of covariance matrix of coordinates of original points Building an OBB Tree

35 Choose bounding box oriented this way Building an OBB Tree

36 Building an OBB Tree: Fitting Covariance matrix of point coordinates describes statistical spread of cloud. OBB is aligned with directions of greatest and least spread (which are guaranteed to be orthogonal).

37 Fitting OBBs Let the vertices of the i'th triangle be the points a i, b i, and c i, then the mean µ and covariance matrix C can be expressed in vector notation as: where n is the number of triangles, and

38 Coffee Break

39 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)

40 To Understand The Arithmetic.. Variance –In fact the same Standard Deviation –The larger, the more sparse

41 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

42 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).

43 Solving the Problem

44 Solving the Problem (cont’d)

45

46 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

47 Good Box Building an OBB Tree

48 Add points: worse Box Building an OBB Tree

49 More points: terrible box Building an OBB Tree

50 Compute with extremal points only Building an OBB Tree

51 “Even” distribution: good box Building an OBB Tree

52 “Uneven” distribution: bad box Building an OBB Tree

53 Fix: Compute facets of convex hull... Building an OBB Tree

54 Better: Integrate over facets Building an OBB Tree

55 … and sample them uniformly

56 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 log 2 n) fitting time for entire tree

57 Tree Traversal Disjoint bounding volumes: No possible collision

58 Overlapping bounding volumes: split one box into children test children against other box Tree Traversal

59

60 Hierarchy of tests

61 Separating Axis Theorem  L is a separating axis for OBBs A & B, since A & B become disjoint intervals under projection onto L

62 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

63 Implications of Theorem Given two generic polytopes, each with E edges and F faces, number of candidate axes to test is: 2F + E 2 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.

64 OBB Overlap Test: An Axis Test s h a b a s h h +> L is a separating axis iff: L h b

65 OBB Overlap Test: Axis Test Details Box centers project to interval midpoints, so midpoint separation is length of vector T’s image.

66 OBB Overlap Test: Axis Test Details Half-length of interval is sum of box axis images.

67 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

68 OBB Overlap Tests: Comparison Benchmarks performed on SGI Max Impact, 250 MHz MIPS R4400 CPU, MIPS R4000 FPU

69 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.

70 Parallel Close Proximity: Convergence 1

71 1 2 / 2 1 4 /

72 1

73 1 2 / 2 1 4 /

74 1

75 1 4 / 1 16 / Parallel Close Proximity: Convergence

76 1 4 / 1 4 / 1 4 /

77 Performance: Overlap Tests OBBs Spheres & AABBs k O(n) 2k O(n 2 )

78 Coffee Break

79 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

80 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

81 Architecture for Multi-body Collision Detection

82 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

83 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

84 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.

85 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)

86 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(n 2 ) matrix

87 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

88 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]

89 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)

90 Dimension Reduction Works better than space partitioning approaches where it is difficult to choose good partition sizes.

91

92 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

93 Multi-bunny Simulation

94 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

95 That’s for today


Download ppt "Collision Detection & Bounding Boxes 數位內容學院 遊戲開發研究班第一期 3D 圖學 沈育德 Edward Shen May 28, 2005."

Similar presentations


Ads by Google