You are on page 1of 36

MIT EECS 6.

837 Computer Graphics

Collision Detection
and Response
MIT EECS 6.837 – Durand
MIT EECS 6.837 – Matusik Philippe Halsman: Dali Atomicus 1
This image is in the public domain. Source:Wikimedia Commons.
Collisions
• Detection
• Response
• Overshooting problem
(when we enter the solid)

2
Collision Response for Particles
v N

3
Collision Response for Particles
v N

vt

vn

v=vn+vt

normal component
tangential component

4
Collision Response for Particles
• Tangential velocity vt v N
often unchanged vt
• Normal velocity vn reflects:
vn

v N vnew
• Coefficient of restitution ε ε=1

• When ε = 1, mirror reflection v N vnew


ε<1

5
Collisions – Overshooting
• Usually, we detect collision when it is too late:
we are already inside
xi

xi+1

6
Collisions – Overshooting
• Usually, we detect collision when it is too late:
we are already inside
• Solution: Back up
xi
• Compute intersection point backtracking
• Ray-object intersection!
• Compute response there
• Advance for remaining
fractional time step

xi+1

7
Collisions – Overshooting
• Usually, we detect collision when it is too late:
we are already inside
• Solution: Back up
xi
• Compute intersection point backtracking
• Ray-object intersection!
• Compute response there fixing
• Advance for remaining
fractional time step
• Other solution: xi+1
Quick and dirty hack
• Just project back to object closest point

8
Questions?
• Pong: ε =?
• http://www.youtube.com/watch?v=sWY0Q_lMFfw
• http://www.xnet.se/javaTest/jPong/jPong.html

Animation removed due to copyright restrictions.

This image is in the public domain. Image courtesy of Chris Rand on Wikimedia Commons. License: CC-BY-SA.
Source:Wikimedia Commons.
This content is excluded from our Creative Commons license. For more info
rmation, see http://ocw.mit.edu/help/faq-fair-use/.

9
Collision Detection in Big Scenes
• Imagine we have n objects. Can we test all pairwise
intersections?
– Quadratic cost O(n2)!

• Simple optimization: separate static objects


– But still O(static × dynamic+ dynamic2)

10
Hierarchical Collision Detection
• Use simpler conservative proxies
(e.g. bounding spheres)

• Recursive (hierarchical) test


– Spend time only for parts of the scene that are close

• Many different versions, we will cover only one

11
Bounding Spheres
• Place spheres around objects
• If spheres do not intersect, neither do the objects!
• Sphere-sphere collision test is easy.

Courtesy of Patrick Laug. Used with permission.


© Gareth Bradshaw. All rights reserved. This content is excluded
from our Creative Commons license. For more information, see
http://ocw.mit.edu/help/faq-fair-use/.

12
Sphere-Sphere Collision Test
• Two spheres, centers C1 and C2, radii r1 and r2
• Intersect only if ||C1C2||<r1+r2

C1 r1 r2 C2

Courtesy of Patrick Laug. Used with permission.


© Gareth Bradshaw. All rights reserved. This content is excluded
from our Creative Commons license. For more information, see
http://ocw.mit.edu/help/faq-fair-use/.

13
Hierarchical Collision Test
• Hierarchy of bounding spheres
– Organized in a tree
• Recursive test with early pruning

Root encloses
whole object
© Gareth Bradshaw. All rights reserved. This content is excluded
from our Creative Commons license. For more information, see
http://ocw.mit.edu/help/faq-fair-use/. 14
Examples of Hierarchy
• http://isg.cs.tcd.ie/spheretree/

© Gareth Bradshaw. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.
15
Pseudocode (simplistic version)
boolean intersect(node1, node2)
// no overlap? ==> no intersection!
if (!overlap(node1->sphere, node2->sphere)
return false

// recurse down the larger of the two nodes


if (node1->radius()>node2->radius())
for each child c of node1
if intersect(c, node2) return true
else
for each child c f node2
if intersect(c, node1) return true

// no intersection in the subtrees? ==> no intersection!


return false

16
boolean intersect(node1, node2)
if (!overlap(node1->sphere, node2->sphere)
return false
if (node1->radius()>node2->radius())
for each child c of node1
if intersect(c, node2) return true
else
for each child c f node2
if intersect(c, node1) return true
return false
node 1
node 2

© Gareth Bradshaw. All rights reserved. This content is excluded


from our Creative Commons license. For more information, see
Courtesy of Patrick Laug. Used with permission.
http://ocw.mit.edu/help/faq-fair-use/. 17
boolean intersect(node1, node2)
if (!overlap(node1->sphere, node2->sphere)
return false
if (node1->radius()>node2->radius())
for each child c of node1
if intersect(c, node2) return true
else
for each child c f node2
if intersect(c, node1) return true
return false

© Gareth Bradshaw. All rights reserved. This content is excluded


from our Creative Commons license. For more information, see
Courtesy of Patrick Laug. Used with permission.
http://ocw.mit.edu/help/faq-fair-use/.
18
boolean intersect(node1, node2)
if (!overlap(node1->sphere, node2->sphere)
return false
if (node1->radius()>node2->radius())
for each child c of node1
if intersect(c, node2) return true
else
for each child c f node2
if intersect(c, node1) return true
return false

© Gareth Bradshaw. All rights reserved. This content is excluded


from our Creative Commons license. For more information, see Courtesy of Patrick Laug. Used with permission.
http://ocw.mit.edu/help/faq-fair-use/.
19
boolean intersect(node1, node2)
if (!overlap(node1->sphere, node2->sphere)
return false
if (node1->radius()>node2->radius())
for each child c of node1
if intersect(c, node2) return true
else
for each child c f node2
if intersect(c, node1) return true
return false

© Gareth Bradshaw. All rights reserved. This content is excluded


from our Creative Commons license. For more information, see
http://ocw.mit.edu/help/faq-fair-use/. Courtesy of Patrick Laug. Used with permission.
20
boolean intersect(node1, node2)
if (!overlap(node1->sphere, node2->sphere)
return false
if (node1->radius()>node2->radius())
for each child c of node1
if intersect(c, node2) return true
else
for each child c f node2
if intersect(c, node1) return true
return false

Courtesy of Patrick Laug. Used with permission.


© Gareth Bradshaw. All rights reserved. This content is excluded
from our Creative Commons license. For more information, see
http://ocw.mit.edu/help/faq-fair-use/.
21
boolean intersect(node1, node2)
if (!overlap(node1->sphere, node2->sphere)
return false
if (node1->radius()>node2->radius())
for each child c of node1
if intersect(c, node2) return true
else
for each child c f node2
if intersect(c, node1) return true
return false

© Gareth Bradshaw. All rights reserved. This content is excluded Courtesy of Patrick Laug. Used with permission.
from our Creative Commons license. For more information, see
http://ocw.mit.edu/help/faq-fair-use/.
22
Pseudocode (with leaf case)
boolean intersect(node1, node2)
if (!overlap(node1->sphere, node2->sphere)
return false

// if there is nowhere to go, test everything


if (node1->isLeaf() && node2->isLeaf())
perform full test between all primitives within nodes

// otherwise go down the tree in the non-leaf path


if ( !node2->isLeaf() && !node1->isLeaf() )
// pick the larger node to subdivide, then recurse
else
// recurse down the node that is not a leaf

return false

23
Other Options
• Axis Aligned Bounding Boxes
– “R-Trees”

• Oriented bounding boxes


– S. Gottschalk, M. Lin, and D. Manocha. “OBBTree: A hierarchical Structure
for rapid interference detection,” Proc. Siggraph 96. ACM Press, 1996

• Binary space partitioning trees; kd-trees

24
Questions?
• http://www.youtube.com/watch?v=b_cGXtc-nMg
• http://www.youtube.com/watch?v=nFd9BIcpHX4&f
eature=related
• http://www.youtube.com/watch?v=2SXixK7yCGU

25
Hierarchy Construction
• Top down
– Divide and conquer

• Bottom up
– Cluster nearby objects

• Incremental
– Add objects one by one, binary-tree style.

26
Bounding Sphere of a Set of Points
• Trivial given center C
– radius = maxi ||C-Pi||

© Gareth Bradshaw. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

27
Bounding Sphere of a Set of Points
• Using axis-aligned bounding box
– center=
((xmin+xmax)/2, (ymin+ymax)/2, (zmin, zmax)/2)
– Better than the average of the vertices because does not
suffer from non-uniform tessellation

© Gareth Bradshaw. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.
28
Bounding Sphere of a Set of Points
• Using axis-aligned bounding box
– center=
((xmin+xmax)/2, (ymin+ymax)/2, (zmin, zmax)/2)
– Better than the average of the vertices because does not
suffer from non-uniform tessellation

Questions?

© Gareth Bradshaw. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.
29
Top-Down Construction
• Take longest scene dimension
• Cut in two in the middle
– assign each object or triangle to one side
– build sphere around it
© Sara McMains. All rights reserved. This content is excluded
from our Creative Commons license. For more information, © Gareth Bradshaw. All rights reserved. This content is
see http://ocw.mit.edu/help/faq-fair-use/. excluded from our Creative Commons license. For more
information, see http://ocw.mit.edu/help/faq-fair-use/.

This image is in the public domain.


Source: Wikimedia Commons.

Courtesy of Patrick Laug. Used with permission.


© Oscar Meruvia-Pastor, Daniel Rypl. All rights reserved. This content is
excluded from our Creative Commons license. For more information,
see http://ocw.mit.edu/help/faq-fair-use/.
30
Top-Down Construction - Recurse
‡ 7DNHORQJHVWVFHQHGLPHQVLRQ
‡ &XWLQWZRLQWKHPLGGOH
± DVVLJQHDFKREMHFWRUWULDQJOHWRRQHVLGH
± EXLOGVSKHUHER[DURXQGLW © Sara McMains. All rights reserved. This content
is excluded from our Creative Commons license.
For more information, see
http://ocw.mit.edu/help/faq-fair-use/.
© Gareth Bradshaw. All rights reserved.
This content is excluded from our Creative
Commons license. For more information,
see http://ocw.mit.edu/help/faq-fair-use/.

This image is in the public domain.


Source: Wikimedia Commons.

© Oscar Meruvia-Pastor, Daniel Rypl. All rightsreserved. This content is


excluded from ourCreative Commons license. For more information, Courtesy of Patrick Laug. Used with permission.
see http://ocw.mit.edu/help/faq-fair-use/. 31
Top-Down Construction - Recurse
‡ 7DNHORQJHVWVFHQHGLPHQVLRQ
‡ &XWLQWZRLQWKHPLGGOH Questions?
± DVVLJQHDFKREMHFWRUWULDQJOHWRRQHVLGH
± EXLOGVSKHUHER[DURXQGLW © Sara McMains. All rights reserved. This content
is excluded from our Creative Commons license.
For more information, see
http://ocw.mit.edu/help/faq-fair-use/.
© Gareth Bradshaw. All rights reserved.
This content is excluded from our Creative
Commons license. For more information,
see http://ocw.mit.edu/help/faq-fair-use/.

This image is in the public domain.


Source: Wikimedia Commons.

© Oscar Meruvia-Pastor, Daniel Rypl. All rightsreserved. This content is


excluded from ourCreative Commons license. For more information, Courtesy of Patrick Laug. Used with permission.
see http://ocw.mit.edu/help/faq-fair-use/. 32
Reference

Image of the cover of the book, "Real Time Collision Detection," by Christer Ericson has been removed
due to copyright restrictions.

33
The Cloth Collision Problem
• A cloth has many points of contact
• Stays in contact
• Requires
– Efficient collision detection
– Efficient numerical treatment (stability)
Image from Bridson et al.

© ACM. All rights reserved. This content is excluded from our Creative Commons
license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.
34
Robust Treatment of Simultaneous Collisions
David Harmon, Etienne Vouga, Rasmus Tamstorf, Eitan Grinspun

Animation removed due to copyright restrictions.

35
MIT OpenCourseWare
http://ocw.mit.edu

6.837 Computer Graphics


Fall 2012

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

You might also like