Motivation - Dynamic Simulation ETH Zurich ETH Zurich • Collision detection is an essential part of physically realistic dynamic simulations.

• For each time step: •compute dynamics • detect collisions • resolve collisions

Stefan Gottschalk, UNC Jim Cremer, Univ of Iowa

Matthias Teschner

M Teschner – Collision Detection GDV 2 – Sommersemester 20021 M Teschner – Collision Detection 2

Motivation - Biomedical Simulation Motivation - Path Planning ETH Zurich ETH Zurich

• Dysfunction of the hip joint due to reoriented femoral head • Restricted range of motion in hip joint Stefan Gottschalk, UNC • Simulation of the range of motion to decide whether a reorienting Jean-Claude Latombe, Stanford Univ osteotomy of the proximal femur can improve the range of motion Planning a path for the torus • Triangulated surface representation of the bone structure involves collision detection tests. -> collision detection problem

M Teschner – Collision Detection 3 M Teschner – Collision Detection 4

1 Motivation Motivation - Robotics ETH Zurich Molecular Motion, Protein Folding ETH Zurich

Sanchez, Latombe, Stanford Univ Singh, Latombe, Brutlag, Stanford Univ

• Collision detection is required to coordinate all tasks for all robots • Computation of low-energy states for designed drug molecules •Can be time-critical in case of a break-down

M Teschner – Collision Detection 5 M Teschner – Collision Detection 6

Outline Bounding Volumes ETH Zurich ETH Zurich

Bounding Volumes Simplified conservative surface representation for fast approximative collision detection test Hierarchies of Bounding Volumes • Spheres • Axis-aligned bounding boxes (ABB) Spatial Partitioning • Object-oriented bounding boxes (OBB) • Discrete orientation (k-DOPs) Distance Fields

Collision Detection • Avoid checking all object primitives. for Deformable Objects • Check bounding volumes to get the information whether objects could interfere.

M Teschner – Collision Detection 7 M Teschner – Collision Detection 8

2 Spheres and Overlapping Test Sphere as ETH Zurich ETH Zurich

Sphere is represented by center c and radius r.

c2

c2 r1

r2

good choice. bad choice. − − > + 2 Two spheres do not overlap if (c1 c2 )(c1 c2 ) (r1 r2 )

M Teschner – Collision Detection 9 M Teschner – Collision Detection 10

Axis-Aligned Bounding Box - ABB ABB as Bounding Volume ETH Zurich ETH Zurich

y ABB is represented by c1 center c and radii rx, ry.

rx2 c2 ry2 x 1 −   > + good choice. bad choice. Two ABBs do not overlap in 2D if (c1 c2 )  rx1 rx2 0 0 −   > + or (c1 c2 )  ry1 ry2 1 M Teschner – Collision Detection 11 M Teschner – Collision Detection 12

3 Discrete Orientation - k-DOP k-DOPs as Bounding Volumes ETH Zurich ETH Zurich

A k-DOP is “a convex polytope whose facets are determined by halfspaces Example: 8-DOP whose outward normals come from a small fixed set of k orientations.” [Klosowski] Larger k’s are more flexible than smaller. ABB is a 4-DOP. Is a 4-DOP an ABB? y k-DOP is represented by k/2 directions and k/2 pairs of min, max values.

min1

max1 x

min2 Two k-DOPs do not overlap, max2 good choice. quite good choice. Examples: if at least the intervals in 6-, 14-, 18-, 26-DOPs one direction do not overlap.

M Teschner – Collision Detection 13 M Teschner – Collision Detection 14

Object-Oriented Bounding Box OBB OBB Overlapping Test in 2D ETH Zurich ETH Zurich

An OBB is represented by the b1B1 Β principal axes of a set of vertices. Α Β A1, A2 , B1, B2 •axes of , These axes are not fixed. They move Α b B • unit vectors according to object transformations. T 2 2 a1,a2 ,b1,b2 • 'radii' of Α,Β a1A1 3 L • unit vector Vertices: vv∈ℜ a2 A2 n = + 1 pA a1 A1L a2 A2 L µ = pA Mean: vi pB n i =1 = + T ⋅ L L pB b1B1L b2 B2 L Covariance matrix: Eigenvectors of the n Α,Β do not overlap: covariance matrix = 1 Cjk vij vik n i=1 ∃ ⋅ > + ∃ ∈ ⋅ > + L : T L pA pB or L {}A1, A2 , B1, B2 : T L pA pB = − µ vi vi 1≤ j, k ≤ 3

M Teschner – Collision Detection 15 M Teschner – Collision Detection 16

4 OBB Examples Bounding Volumes - Summary ETH Zurich ETH Zurich

• Principal axes of an object are not always a good choice for the main axes of an OBB! • Spheres • Inhomogeneous vertex distribution • Axis-aligned bounding boxes (ABB) can cause bad OBBs. • Object-oriented bounding boxes (OBB) • Discrete orientation polytopes (k-DOP’s)

• Ellipsoids PSS •Convex Hulls • Swept-Sphere Volumes (SSV’s) • Point Swept Spheres (PSS) • Line Swept Spheres (LSS) • Rectangle Swept Spheres (RSS) • Triangle Swept Spheres (TSS) Lin, UNC LSS RSS

M Teschner – Collision Detection 17 M Teschner – Collision Detection 18

The Optimal Bounding Volume ? Outline ETH Zurich ETH Zurich

Bounding Volumes

Hierarchies of Bounding Volumes

Spatial Partitioning Sphere ABB OBB 6-DOP Convex Hull Distance Fields Quality: Better approximation Collision Detection Decreasing complexity and computational expenses for Deformable Objects

M Teschner – Collision Detection for overlap test 19 M Teschner – Collision Detection 20

5 Hierarchy of Bounding Volumes Hierarchy of Bounding Volumes ETH Zurich ETH Zurich

• Not only one bounding volume, but a hierarchical structure of BV for the bounding volumes entire object

• Subdivsion of bounding volumes to generate a hierarchy BV • Bounding volume tree BV for parts Layer 1 Layer 2 Layer 3 (BV tree) of the object •Nodes contain BV BV bounding volume information • Leaves additionally BV BV contain information BV for a few/one primitives on object primitives object primitive(s)

primitives primitives

M Teschner – Collision Detection 21 M Teschner – Collision Detection 22

Hierarchy of Bounding Volumes - OBB Tree Example ETH Zurich ETH Zurich

Object-oriented bounding box level 1

Object Object-oriented bounding boxes level n

• Sean Quinlan, Stanford Univ • Philip Hubbard, Brown Univ M Teschner – Collision Detection 23 M Teschner – Collision Detection 24

6 ABB vs. OBB Tree Overlapping Test for BV Trees ETH Zurich ETH Zurich • BV-trees speed-up the collision detection test Representation • If bounding volumes in a hierarchy level overlap, their children are of a torus checked for overlapping. If leaves are reached, primitives are checked against each other.

Lin, UNC Chapel Hill

M Teschner – Collision Detection 25 M Teschner – Collision Detection 26

Construction of a BV Tree Construction of a BV Tree ETH Zurich ETH Zurich

Bottom-Up Parameters

• Start with object-representing primitives • Bounding volume • Fit a bounding volume to each primitive • Top-down vs. bottom-up • Group primitives or bounding volumes recursively • What to subdivide / group: object primitives or bounding volumes • Fit bounding volumes to these groups • How to subdivide / group object primitives or bounding volumes • Stop in case of a single bounding volume at a hierarchy level • How many primitives in each leaf of the BV tree • Re-sampling of the object ? Top-Down •Start with object Goals • Fit a bounding volume to the object • Split object or bounding volume recursively • Balanced tree • Fit bounding volumes • Tight-fitting bounding volumes • Stop, if all bounding volumes in a level contain less than n primitives • Minimal redundancy (primitives in more than one BV per level)

M Teschner – Collision Detection 27 M Teschner – Collision Detection 28

7 Construction of a BV Tree - Spheres Collision Detection Libraries ETH Zurich ETH Zurich

Hubbard: SOLID RAPID QuickCD • Approximate triangles with spheres and build the tree bottom-up by grouping spheres Axis-aligned Object-oriented k discrete • Cover vertices with spheres and group them bounding box bounding box orientation • Resample vertices prior to building the tree polytope (homogeneous vertex distribution reduces redundancy) • Build the tree top-down by using an octree • Compute the medial axis and place spheres on it

medial axis van den Gottschalk Klosowski based Bergen et al. et al. Eindhoven University of University of University North Carolina New York octree based 1997 1995 1998

M Teschner – Collision Detection 29 M Teschner – Collision Detection 30

Comparison of CD Libraries Object Transformations ETH Zurich ETH Zurich • Time to compute a collision for two spheres with radius 1 cm • Translation represents the distance of both centers Some object transformations can be simply applied • QuickCD [Klosowski], RAPID [Gottschalk], SOLID [Bergen] to all elements of the bounding-volume tree: • Differences mostly due to programming aspects Spheres • Translation, rotation

Axis-Aligned Bounding Boxes • Translation, no rotation

Discrete Orientation Polytopes 10,000 triangles • Translation, no rotation per sphere (principal orientations are fixed for all objects) 8-DOP OBB Object-Oriented Bounding Boxes ABB • Translation, rotation (box orientations are not fixed) M Teschner – Collision Detection 31 M Teschner – Collision Detection 32

8 Rotations Parallel Close Proximity ETH Zurich ETH Zurich

Axis-Aligned Bounding Boxes Discrete Orientation Polytopes • Quality of lower-level • Rotation of the bounding volume is not BV approximation possible due to the respective box overlap test. influences collision (The tests require fixed surface normals.) detection performance in case of close proximity. Problem Spheres 1. Recomputation of the BV hierarchy • Quality of higher-level 2. Preservation of the tree structure, update of all nodes BV approximations is 3. Additional storage of the convex hull which is rotated with the object not very critical. - check if extremal vertices are still extremal after rotation • In case of overlapping BV - compare with adjacent vertices of the convex hull expensive primitive tests - “climb the hill” to the extremal vertex have to be performed. 4. Computation of an approximate box by rotating the box and checking the rotated box for extremal values ABB, k-DOP OBB

M Teschner – Collision Detection 33 M Teschner – Collision Detection 34

Hierarchical Bounding Volumes - Outline Summary ETH Zurich ETH Zurich

• Bounding volume tree (BV tree) based on spheres or boxes • Nodes contain bounding volume information Bounding Volumes • Leaves additionally contain information on object primitives Hierarchies of Bounding Volumes • Isolating interesting regions by checking bounding volumes in a top-down strategy Spatial Partitioning • Construction of a balanced, tight-fitting tree with minimal redundancy Distance Fields • Transformation of BV trees dependent on the basic bounding volume Collision Detection • Optimal bounding box hierarchy dependent on application for Deformable Objects (e. g. close proximity problem)

M Teschner – Collision Detection 35 M Teschner – Collision Detection 36

9 Bounding Volume Hierarchy vs. Spatial Data Structures

Spatial Partitioning ETH Zurich for Collision Detection ETH Zurich

Bounding Volume Hierarchy

Spatial Partitioning

uniform grid quadtree / octree kd-tree BSP-tree

• Each cell contains information whether it is occupied by Object related World (space) related an object -> Possible collision! • Information is updated for each object transformation. • quadtree, kd-tree, and BSP-tree are hybrid approaches. They subdivide space, but object-dependent.

M Teschner – Collision Detection 37 M Teschner – Collision Detection 38

Uniform Grid Graphics Hardware for 2D Collisions ETH Zurich ETH Zurich

• Each cell contains information which objects are in it. • Kenneth Hoff, UNC -> Possible collision! frame buffer • Stencil-buffer for collision detection is a uniform grid • Clear stencil buffer obj 1 empty empty obj 2 empty empty obj 2 • Increment stencil buffer for each rendered object obj 1 obj 1 empty obj 1 empty empty • Intersection for stencil buffer value larger 1 obj 2 obj 2

empty obj 1 obj 1 obj 2 empty empty

empty obj 1 obj 1 obj 2 empty empty

empty obj 1 obj 1 empty empty empty stencil value 1 stencil empty empty empty empty empty empty value 2 Hoff, UNC M Teschner – Collision Detection 39 M Teschner – Collision Detection 40

10 Graphics Hardware for 3D Collisions Outline ETH Zurich ETH Zurich

• George Baciu, Hong Kong University • Stencil-buffer for collision detection • Clear stencil buffer Bounding Volumes • Increment stencil buffer for each rendered object Hierarchies of Bounding Volumes • Possible intersection for stencil buffer value larger 1 Spatial Partitioning •Checking z-intervals for candidate frame buffer positions z1 Distance Fields

stencil z Collision Detection value 1 for Deformable Objects stencil value 2 min z2min z1max z2max

M Teschner – Collision Detection 41 M Teschner – Collision Detection 42

Distance Fields Distance Field Generation ETH Zurich ETH Zurich

• Susan Fisher, Ming Lin, UNC 000 • Distance field: Minimal distance from 0 0 • Fast generation of distance fields 1 each point within an object to the by using level set method object surface, outside points are zero 0 1 1 1 1 0 v • Initialization of a narrow band • Distance field is transformed with area with distance values 0 1 2 2 1 0 respect to object transformation • Consideration of the surface as a moving wave • Primitives of other objects are checked v • Computing the arrival time for 0 1 2 2 1 0 against the distance field of an object each point inside the object • -> value larger 0 -> collision v 0 1 1 1 0 0 (linear proportional to the distance • Distance value represent penetration to the original surface) 0 0 0 0 00 depth and can be used for collision •Very fast response, e.g. penalty forces. • Time / distance is derived from adjacent values narrow band area

M Teschner – Collision Detection 43 M Teschner – Collision Detection 44

11 Distance Fields - Applications Outline ETH Zurich ETH Zurich

• Susan Fisher, Ming Lin, UNC • Collision detection based on distance fields for deformable objects Bounding Volumes

Hierarchies of Bounding Volumes

Spatial Partitioning

Distance Fields

Fisher, UNC Collision Detection for Deformable Objects

Fisher, UNC

M Teschner – Collision Detection 45 M Teschner – Collision Detection 46

Collision Detection for Sphere Trees for Deformable Objects ETH Zurich Deformable Objects ETH Zurich

• Stephen Sorkin, J.C. Latombe, Stanford Univ Bounding Volume Hierarchy • Problem: Sphere tree has to be updated in case of object deformation • Time-consuming generation of hierarchies • Bottom-up approach for updating the • Preprocessing step in case Spatial Partitioning tree • Same handling of rigid and of rigid bodies • Update of leafs only for deformable bodies • Focus on quality of the deformed primitives • No preprocessing approximation • Propagating leaf information to the • (Partly) update of the hierarchy root required in case of deformation

M Teschner – Collision Detection 47 M Teschner – Collision Detection 48

12 Summary References ETH Zurich ETH Zurich • S. Quinlan, “Efficient Distance Computation Between Non-Convex Objects,” Hierarchies of Bounding Volumes Proc. Int. Conf. on Robotics and Automation, pp. 3324-3329, 1994. Simplification of collision detection by • P. M. Hubbard, “Approximating Polyhedra With Spheres for Time-Critical using approximate bounding volumes Collision Detection,” ACM Transactions on Graphics, 15 / 3, pp. 179-210, 1996. (spheres, boxes, … ) • S. Gottschalk, M. C. Lin, D. Manocha, “OBBTree: A Hierarchical Structure for Rapid Interference Detection,” Proc. SIGGRAPH’96, ACM , Spatial Partitioning New York, NY, USA, pp. 171-180, 1996. Using information about the position of • G. van den Bergen, “Efficient Collision Detection of Complex Deformable object primitives for collision detection Models using AABB Trees,” Journal of Graphics Tools, 2 / 4, pp. 1-13, 1997. Distance Fields • J. T. Klosowski et al., “Efficient Collision Detection Using Bounding Volume 000 Hierarchies of k-DOPs,” IEEE Trans on Vis and Computer Graphics, 4 / 1, Computation of surface distance for all 0 1 0 pp. 21-36, 1998. object points 0 1 1 1 1 0 • S. Fisher, M. Lin, ”Deformed Distance Fields for Simulation of Non-Penetrating 0 1 2 2 1 0 Simulation (CAS), Collision Detection for Deformable Objects Flexible Bodies,” Eurographics Workshop on Computer Animation and 0 1 2 2 1 0 Distance fields, bounding volume hierarchies, September 2001. 0 1 1 1 0 spatial partitioning 0 • G. Baciu, S. K. Wong "Image-Based Techniques in a Hybrid Collision Detector," 0 0 000 0 IEEE Transactions on Visualization and Computer Graphics, Jan 2002. M Teschner – Collision Detection 49 M Teschner – Collision Detection 50

13