Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final...

47
Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson

Transcript of Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final...

Page 1: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Efficient and Accurate Collision Detection Hierarchies with Collision

Response

CSE530/CSE631 Final Demo

Evan Closson

Page 2: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Past Work – Collision Detection

• Many efficient bounding volume hierarchies have been created.• Spheres: “Approximating Polyhedra with Spheres for Time-Critical Collision

Detection,” Philip M. Hubbard. ACM Transactions on Graphics, Vol. 15, No 3, July 1996, Pages 179-210.

• AABBs: “Efficient Collision Detection of Deformable Models using AABB Trees,” Gino van den Bergen, Journal of Graphics Tools, 2(4):1-14, 1997.

• k-dops also known as discrete orientation polytopes: ``Efficient Collision Detection Using Bounding Volume Hierarchies of k-DOPs'', J.T. Klosowski, M. Held, J.S.B. Mitchell, H. Sowizral,

• K. Zikan, IEEE Trans. Visualizat. Comput. Graph. 4(1):21-36, Jan 1998.• OBB: “OBB-Tree: A Hierarchical Structure for Rapid Interference Detection,”

S. Gottschalk, M. Lin, and D. Manocha. Proc. ACM SIGGRAPH, 1996.

Evan Closson Spring 2003

Page 3: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Past Work – Collision Response

• D. Baraff. Analytical methods for dynamic simulation of non-penetrating rigid bodies. Computer Graphics 23(3): 223-232, 1989.

• D. Baraff. Coping with friction for non-penetrating rigid body simulation. Computer Graphics 25(4): 31-40, 1991.

• D. Baraff and A. Witkin. Dynamic simulation of non-penetrating flexible bodies. Computer Graphics 26(2): 303-308, 1992.

Evan Closson Spring 2003

Page 4: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Detection

• Well researched.

• Very fundamental to many areas specifically simulated environments.

• Determine if a collision occurs.

• Determine the points of impact.

Evan Closson Spring 2003

Page 5: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Bounding Volume Hierarchies

• Often models are very geometrically complex.

• Need efficient queries of the kind: do these two bodies A and B collide and at what point?

• Bounding Volume Hierarchies can approximate a model to a arbitrary level of detail depending upon the depth of the tree.

Evan Closson Spring 2003

Page 6: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Sphere Trees

• Difficult to tightly fit to objects, need many spheres.

• Very efficient collision checks

Evan Closson Spring 2003

Page 7: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Octree Creation

• Very simple creation method, not very great fitting to objects.

• Build octree from bounding box of model.• Traverse octree and at each node create a

sphere – if needed – that contains all the geometry in that node.

• Different sampling methods can be used to increase the accuracy of the sphere creation.

Evan Closson Spring 2003

Page 8: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Medial Axis Creation

• The medial axis – or skeleton of a structure can be used to more smartly place bounding spheres for an arbitrarily shaped geometry.

• Medial axis is the Voronoi diagram of the edges interior to the polygon. In 3D it is the surfaces.

Evan Closson Spring 2003

Page 9: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Medial Axis Creation• Complex algorithm, but briefly . . .• Approximate Medial Axis with Voronoi diagram

of the vertices.• Create lowest level of spheres in structure from

the medial axis.• Create the bounding root sphere.• Knowing the number of children to use, merge

neighboring spheres – found from Voronoi info – to create each level of the tree structure.

Evan Closson Spring 2003

Page 10: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Sphere Sphere Collision

• If the length between the two spheres center is less then the radii summed then a collision has occurred.

Evan Closson Spring 2003

l lr

rr

r

Page 11: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Sphere Sphere Collision

Evan Closson Spring 2003

//bool SphereSphere(Model & m1, Model & m2, SPHERE & a, SPHERE & b){

float rs = a.r + b.r;Vector apos = m1.Trans(a.loc);Vector bpos = m2.Trans(b.loc);Vector dist = apos – bpos;return dist.MagSq() <= rs*rs;

}

Page 12: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Time

• We are not working with continuous time

• Time is a sampled domain.

• Each iteration steps through time by one time step.

• Sampling error can occur.

• The exact collision time can be between time steps.

Evan Closson Spring 2003

Page 13: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Time

Evan Closson Spring 2003

ti

ti + 1

ti + 0.7

Page 14: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Time

• Can use a higher sampling rate – smaller time step.• Can use a binary search or bisector method.• If at simulation time ti + 1 a collision is detected we move

the simulation time back to ti +.5 and test again.• If a collision is again detected try between ti and ti +.5 else

try between ti +.5 and ti + 1.• Repeat this until accuracy desired is reached.• Other methods are also used that try and predict the time

of collision.

Evan Closson Spring 2003

Page 15: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Point

• Detecting the collision point is important for the collision response depends on this information.

• The points of collision on the two bodies in colliding contact are known, these are the leafs in the collision tree that were colliding.

Evan Closson Spring 2003

Page 16: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Point

• Response system depends on one point of contact between two colliding bodies.

• Or else the order in which we submit the collision points will make a difference to the impulse based response.

• To achieve this all the points in contact are averaged.

• This gives decent results.

Evan Closson Spring 2003

Page 17: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Point

• Also need to find the line of action of the collision.

• This can be estimated by simply taking distance vector connecting the two collision points in world space. Normalize this so we have the line of action.

• The tangent to this can also be taken and can be used to estimate the friction.

Evan Closson Spring 2003

Page 18: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Point

• Finally the relative velocity between the two colliding points must be found. This is the difference between the local/body space velocity of each of the two colliding points.

• This information is then sent onto the collision response system.

Evan Closson Spring 2003

Page 19: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Collision Response

• What happens when two bodies collide?

• Impulse Based

• Penalty Methods

Evan Closson Spring 2003

Page 20: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Mass Properties

• Needed in the calculations for motion.

• They define the resistance of a body to motion. For example: a = F/m

• Mass, Center of Mass, Moment of Inertia

Evan Closson Spring 2003

Page 21: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Mass

• The volume integral over a continuous body to find the total mass. Density = ρ.

• Truly found by summing up the mass of every element in a body.

• We estimate these with mass-points, often just a mass value at a vertex.

Evan Closson Spring 2003

M = ∫ ρdV M = ∑ mi

Page 22: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Center of Mass

• Formulation for calculating the center of mass over a continuous body.

• Calculating the COM from mass-points. Each mass-point is weighted by it’s position in object space.

Evan Closson Spring 2003

COM = ∫ xyz dm COM = (∑ pimi)/M

Page 23: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Moment of Inertia

• Mass is a resistance to linear motion while moment of inertia is a resistance to rotational motion.

• The moment of inertia is defined with respect to the axis of rotation of the object where r is the distance to the axis of rotation.

• This is actually very difficult to compute for arbitrary shapes, the axis of rotation changes and can take into account any of the degrees of freedom that the object has.

• In 3D we can represent this with an Inertia Tensor defined with respect to local/body space.

Evan Closson Spring 2003

I = ∫ r^2 dm

Page 24: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Inertia Tensor• First to compute the inertia tensor a body must be

broken up into mass-points. • Define a local moment of inertia for each mass

point. • Simple symmetric shapes are more easily defined.• If a mass-point is assumed to be a simple shape

such as a sphere this can be done with the simple formula: I = (2/5)mR^2

• Here I is a vector and defines the inertia with respect to the x, y, and z axis, since a sphere is symmetric this is all that is needed.

Evan Closson Spring 2003

Page 25: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Inertia Tensor

Evan Closson Spring 2003

I = ∑ M(i)

e1 e4 e7 M(i) = e2 e5 e8 e3 e6 e9

e1 = Ixi + mi * (yi^2 + zi^2) e2 = e4 = -(mi * xi * yi) e3 = e7 = -(mi * xi * zi) e5 = Iyi + mi * (xi^2 + zi^2) e6 = e8 = -(mi * yi * zi) e9 = Izi + mi * (xi^2 + yi^2)

Here each i subscript denotes a mass-point’s value and Ix,y,z denotes the local inertial value for each mass point.

Page 26: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Motion

• Linear Motion, really the bodies center of mass displacement which may not be linear.

• Angular Motion (the movement of a body about it’s center of mass)

Evan Closson Spring 2003

Page 27: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Linear Motion

• The formulas for acceleration, velocity, and displacement.• In simulations these are broken down into minute linear

steps so we can make use of linear equations for motion.

Evan Closson Spring 2003

a = F/mv = ds/dts = ∫ v dt

∆v = a*∆t (if a is constant - linear)s = v0 + 1/2at^2 (if linear)

Page 28: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Angular Motion

• Same approach as for linear motion. The equations relate directly. Instead of force we are working with torque, and instead of mass we are using the moment of inertia.

• This is also done with minute steps.

Evan Closson Spring 2003

α = I^-1τω = dΩ/dtΩ = ∫ ω dt

∆ ω = α *∆t Ω = ω0 + 1/2at^2

Page 29: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Integrating Motion

• Estimating the equations of motion with minute linear steps causes errors.

• Larger time steps cause more error, while smaller ones cause less.

• Smaller time steps are not always feasible because of time constraints.

• There are different methods to estimate the equations of motion the most common methods rely upon the Taylor series.

Evan Closson Spring 2003

Page 30: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Taylor Series Methods

• The Taylor series can be used to approximate these functions of motion.

• The higher the order summed to in the Taylor series the more accurate the approximation.

• Here n is the order of the infinite series, for a summation from 0 to ∞.

• We can stop this at any n, the more accurate the approximation the larger n.

• The error in the approximation is the amount of the series left over.

Evan Closson Spring 2003

f(x) = ∑(fn(a)/n!)(x – a)^n

Page 31: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Taylor Series Expanded

• The series expanded to order n for velocity as a function of time.

• The more accurate the more we have to expand.• It is hard to know the derivatives for motion past order 1 well

but they can often be approximated.• The most basic and well known method for this type of

integration is Euler’s Method. In this case the expansion is order one.

Evan Closson Spring 2003

v(ti + dt) = v(ti) + dt v’(ti) + (dt^2/2!)v’’(ti) + (dt^3/3!)v’’’(ti) + … +

(dt^n/n!)vn(ti)

Page 32: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Euler’s Methods

• The Taylor series of order one, Euler’s method for integration. We know the first derivative the acceleration.

• Easy but also the most error prone.

Evan Closson Spring 2003

v(ti + dt) = v(ti) + dt v’(ti)vi = vi-1 + a*dt

Page 33: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Other Methods

• Difficulty in computing the higher order derivatives.

• Runge-Kutta methods can be used to approximate higher order Taylor series using linear combinations to approximate their derivatives.

• One of the most common Runge-Kutta methods is the fourth order method which approximates the Taylor series to order 4.

Evan Closson Spring 2003

Page 34: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Integrating Motion – Euler Code

// linear motionm_Acceleration = m_Force/m_Massm_Velocity += m_Acceleration * dt;m_Location += m_Velocity * dt;

// angular motionm_AngularAcceleration = m_InertiaInverse * m_Torquem_AngularVelocity += m_AngularAcceleration * dt;m_Orientation += (m_Orientation*m_AngularVelocity)*(0.5f * dt);m_Orientation.Normalize();

Page 35: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Impulse

• Impulse is the change in momentum. • Applying an impulsive force to a body will change

the velocity.• Using the information provided by the collision

detection we can calculate an impulse based upon the current state of a two bodies A and B.

Evan Closson Spring 2003

p = mvJ = ∆p = Favg * ∆t

Page 36: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Implementing Linear Impulse

• Although linear impulse is not enough to represent angular motion as well it is a good first place to look to understand how implementing the impulse is done.

• The above formula show how to calculate a new velocity vi from the old velocity and the impulse.

Evan Closson Spring 2003

vi = vi-1 + J/m

Page 37: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Solving for J

• J can be broken up into both it’s magnitude and direction, which is the normal of the collision.

• We know n from the results of the collision detection.

• Now the magnitude j must be computed.

Evan Closson Spring 2003

J = jn

Page 38: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Solving for j (magnitude)

• The top equations solves the relative velocity of the colliding points for two objects A and B after the impulse is applied.

• -e is the coefficient of restitution and can be used to estimate the softness of an object.

• e ranges from 0 to 1, 1 is a mean no deformation of the objects at collision so no energy loss, 0 means complete energy loss.

• The second equation shows the definition of the relative velocity where vai and vbi is the velocity of object a and b and time i.

Evan Closson Spring 2003

vreli = -evreli-1

vreli = n · (vai – vbi)

Page 39: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Solving for j (magnitude)

• Using some substitutions.

Evan Closson Spring 2003

vi = vi-1 + J/mJ = jnvi = vi-1 + jn /mvreli = n · (vai – vbi)vreli = n · (vai-1 + jn /ma – vbi-1 + jn /mb)

Page 40: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Solving for j (magnitude)

• Solving for j.• Now we know J = jn and can use the formula vi = vi-1 + J/m can to

apply the impulse to change the velocity.• Object A get J and object B get –J.

Evan Closson Spring 2003

vreli = -evreli-1

-evreli-1 = n·[(vai-1 + jn/ma) – (vbi-1 - jn/mb)]-evreli-1 = n·(vai-1 - vbi-1) + j(n/ma + n/mb)-evreli-1 = vreli-1 + j(n/ma + n/mb)-evreli-1 - vreli-1 = j(n/ma + n/mb)-(e + 1)vreli-1 = j(n/ma + n/mb)j = [-(e + 1)vreli-1]/ (n·n * (1/ma + 1/mb))

Page 41: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Implementing Angular Impulse

• These are the formulas for change in angular velocity and impulsive torque, where r is the distance from the point of contact to the axis of rotation.

• Calculating the impulse J that can be used for a collision response with rotations must take into considerations the rotational velocity of the colliding points as well as the linear velocity.

Evan Closson Spring 2003

∆ω = τimp * I^-1ωi = ωi-1 + τimp * I^-1

τimp = r x J

Page 42: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Implementing Angular Impulse

• We can break down J the exact same way as before the difference is that here vreli is not defined just by the linear velocity of the body but also by the rotational velocity of the colliding points.

Evan Closson Spring 2003

vreli = n · (pai – pbi)p = v + ω x r

Page 43: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Implementing Angular Impulse

• Showing the equations used in substitution.• Now we can have pai and pbi defined by their previous linear and

angular velocity.• We substitute these back into the relative velocity equation the same

way we did for linear motion and solve for j.

Evan Closson Spring 2003

vi = vi-1 + jn/m ωi= ωi-1 + [r x (jn/m)] * I^-1

pi = vi + ωi x rvreli = -evreli-1

vreli = n · (pai – pbi)

Page 44: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Implementing Angular Impulse

And we get . . .

Evan Closson Spring 2003

t1 = 1/ma + 1/mb

t2 = n · [(Ia^-1 * (ra x n)) x ra]t3 = n · [(Ib^-1 * (rb x n)) x rb]j = [-(e + 1)vreli-1]/ (t1 + t2 + t3)

Find J and then we can find the new linear and angular velocity.

Page 45: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

Results

Evan Closson Spring 2003

Final Project

Page 46: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

References

Evan Closson Spring 2003

• [HECHT96]: “Physics Calculus,” Eugene Hecht. Brooks/Cole Publishing Company, 1996.• [BOURG02]: “Physics for Game Developers,” David M. Bourg. O’Reilly & Associates, Inc,

2002.• [HUBBARD96]: “Approximating Polyhedra with Spheres for Time-Critical Collision

Detection,” Philip M. Hubbard. ACM Transactions on Graphics, Vol. 15, No 3, July 1996, Pages 179-210.

• [BERG00]: “Computational Geometry: Algorithms and Applications,” Mark de Berg, Marc van Kreveld, Mark Overmars, Otfried Schwarzkopf. Springer-Verlag, 2nd rev. ed. 2000.

• [O’ROURKE98]: “Computational Geometry in C (2nd Ed.),” Joseph O'Rourke. Cambridge University Press, September 1998.

• [LANDER00]: “Collision Response: Bouncy, Trouncy, Fun,” Jeff Lander. Gamasutra, 2000.• [BOBIC00]: “Advanced Collision Detection Techniques,” Nick Bobic. Gamasutra, 2000.• [KLOSOWSKI98]: ``Efficient Collision Detection Using Bounding Volume Hierarchies of k-

DOPs'', J.T. Klosowski, M. Held, J.S.B. Mitchell, H. Sowizral, • K. Zikan, IEEE Trans. Visualizat. Comput. Graph. 4(1):21-36, Jan 1998.• [BARAFF89]: “Analytical Methods for Dynamic Simulation of Non-Penetrating Rigid

Bodies,” David Baraff. Computer Graphics, Volume 23 Number 3, July 1989, SIGGRAPH 1989.

Page 47: Efficient and Accurate Collision Detection Hierarchies with Collision Response CSE530/CSE631 Final Demo Evan Closson.

References

Evan Closson Spring 2003

• [BARAFF97]: “Physically Based Modeling: Principles and Practice,” Andrew Witkin  and David Baraff. Online Course Notes for SIGRAPH 97, http://www-2.cs.cmu.edu/~baraff/ sigcourse/ index.html.

• [BRADSHAW03]: “Sphere-Tree Construction Toolkit,” Gareth Bradshaw http://isg.cs.tcd.ie/spheretree/, 2003.

• [BRADSHAW02]: “Sphere-Tree Construction Using Dynamic Medial Axis Approximation,” Bradshaw, G. and O'Sullivan, C. ACM SIGGRAPH Symposium on Computer Animation SCA 2002.

• [VAN DEN BERGEN97]: “Efficient Collision Detection of Deformable Models using AABB Trees,” Gino van den Bergen, Journal of Graphics Tools, 2(4):1-14, 1997.

• [GOTTSCHALK96]: “OBB-Tree: A Hierarchical Structure for Rapid Interference Detection,” S. Gottschalk, M. Lin, and D. Manocha. Proc. ACM SIGGRAPH, 1996.

• [KAISER00]: “3D Collision Detection,” Kevin Kaiser. Game Programming Gems, Charles River Media, 2000. Pgs 391-402.

• [OLSEN00]: “Interpolation Methods,” John Olsen. Game Programming Gems, Charles River Media, 2000. Pgs 141-149.

• [GOMEZ00a]: “Integrating the Equations of Rigid Body Motion,” Miguel Gomez. Game Programming Gems, Charles River Media, 2000. Pgs 150-160.

• [GOMEZ00b]: “Using Implicit Euler Integration for Numerical Stability,” Miguel Gomez. Game Programming Gems, Charles River Media, 2000. Pgs 177-181.