10-Collision Response Collision Response Collision Response [Moore - - PowerPoint PPT Presentation
10-Collision Response Collision Response Collision Response [Moore - - PowerPoint PPT Presentation
10-Collision Response Collision Response Collision Response [Moore and Wilhelms 88]: automatic suggestions about the motions of objects immediately following a collision; animation systems using dynamical simulation inherently must respond
Collision Response
Collision Response [Moore and Wilhelms 88]: “automatic suggestions about the motions of objects
immediately following a collision; animation systems using dynamical simulation inherently must respond to collisions automatically and realistically” Intersection/contact information alone (i.e. Yes/no answer to whether objects are colliding) is very useful for interaction, picking, collision avoidance etc. In self-regulating dynamic simulations (e.g. virtual environments) collisions are the basis for interaction between different objects, between users and objects
Problems of Collision Response
In Physically Based Animation, objects need to behave in ways similar to their real-world counterparts
We need to ensure that objects react according to believable dynamics We need to enforce non-interpenetration
Collisions are a source of unpredictable simulation
- discontinuities. As a result they create additional
workload for the simulation mechanism.
Rigid Body Representation
RigidBody Mass = m InertialTensor = IBODY Position = x(t) Orientation = R(t) LinearMomentum = P(t) AngularMomentum = L(t) Force = F(t) Torque = t(t)
Y(t)= Simulation involves finding the change of Y over time:
*Baraff, Witkin, Kass ‘01+
Rigid body geometry
for collision detection, mass distribution: Inertial tensor I, center of mass
) ( ) ( ) ( * ) ( ) ( ) ( ) ( ) ( ) ( ) ( t t t t t t t t t dt d t dt d τ F R ω v L P R x Y
Dynamics Proxy Display Mesh
Integrating Rigid Body State
) ( ) ( ) ( * ) ( ) ( ) ( ) ( ) ( ) ( ) ( t t t t t t t t t dt d t dt d τ F R ω v L P R x Y
P(t) : Linear Momentum = mv(t) L(t) : Angular Momentum = I(t)w(t)
) ( ) ( ) ( * ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( t t t t t t t t m t t dt d t dt d τ F R ω v w I v R x Y
Spring Based Response
Places a virtual spring at each collision point to push two objects apart Easy to understand and program, applies equally well to rigid and non-rigid bodies Numerical effort increases with violence of collision (smaller time-steps required) A.K.A. Penalty methods
Objects allowed to penetrate Spring force proportional to interpentration
Collision events
Soft Collision
Hard Collision
Impulse
Impulse-based Collision Response
Collision events are discontinuities in the Simulation Loop An instantaneous change of Rigid-Body state Quick local calculation of instantaneous change in velocities is possible at contact points Good solution for rigid body impact but it is difficult to accurately model resting contact and static friction
Rigid Body Collisions
Collisions are a source of discontinuity in the simulation process Particularly in the case of rigid bodies we need to compute an (almost) instantaneous change in state at the time of collision to prevent colliding objects from penetrating
Steady simulation is interrupted by discontinuity due to collision Discontinuity
Physics Pipeline With Collisions
Constraint based methods
Makes a distinction between contact and collisions For objects moving towards each other (negative relative velocities), force applied over time is often not enough to prevent interpenetration Changing nature of constraints can cause high computational demand
mg F
For two objects in contact (relative velocity 0) ensure that the right force is applied to prevent them from interpenetrating
Particle Plane (Impulse response)
- v
v
V- V+
v J v m ˆ
.v n n J ˆ j n J ˆ j
Change in velocity caused by application of an Impulse in direction normal to plane, and
- f magnitude j
1 j
- ||
||
v v
..... (1)
Rigid Body Impulse
Linear component
Similar to particles causing change in velocity inversely proportional to mass as if force was applied at c.o.m.
Angular component
Causes change in angular velocity inversely proportional to moment (determined from inertial tensor) Dependent on position of impulse
m J v
Effect of an impulse (or for that matter a force) on objects linear and angular momentum is independent x(t) p(t) x(t)
) J (r I ω
1
) ) ( J x p ( I
1
Impulsive Torque
But what is the value of J?
Rigid Body Collision
p xb xa
b a
p p p
C
rel rel
v v ) ( ˆ
b a rel
p p n v
N.B Relative velocity of colliding points on two object is the input into the magnitude of the impulse. How do we get this? May be collocated but pa and pb are separate points on respective objects with different velocities
Aside: Angular Velocity
Angular velocity: rate at which orientation changes Think of it as magnitude w and axis A Instantaneous speed of a point p on circle (radius r) due to its rotation is: Linear Velocity :
) ( ) ( t t w A A ω ) ( ) ( ) ( t t t w
Speed at which changes A w
r t t p ) ( ) ( w ) ( ) ( ) ( t t t r ω v
- p
) ) ( ( ) ( ) (
- p
ω v t t t
Rigid Body Collision
p xb xa
rel rel
v v ) ( ˆ
b a rel
p p n v
) x (p ω v p
b b b b b
) x (p ω v p
a a a a a
Linear velocity component Linear velocity of point p due to its rotation. See previous slide
Collision Impulse
a a a a
r ω v p
Post-collision velocity should be We want to compute this in terms
- f previous state of object (pre-
collision values)
a a a
m j v n v ˆ
) ˆ ( n r I ω ω j
a 1 a a a
a a 1 a a a a a
j m j r n r I ω n v p
ˆ ˆ
a a 1 a a a a a
m j r n r I n r ω v
ˆ ˆ
a a 1 a a a a
m j r n r I n p p
ˆ ˆ
b b 1 b b b b
m j r n r I n p p
ˆ ˆ
Similarly (by Newton 3):
Collision Impulse Magnitude
) ( ˆ
b a rel
p p n v
rel rel
v v
n v ˆ
rel
a a 1 a a a
m j r n r I n p
ˆ ˆ
b b 1 b b b
m j r n r I n p
ˆ ˆ
b b 1 b a a 1 a b a b a rel
m 1 m 1 j r n r I n r n r I n p p n v ˆ ˆ ˆ ˆ ) ( ˆ
b b 1 b a a 1 a b a rel rel
m 1 m 1 j r n r I n r n r I n v v ˆ ˆ ˆ ˆ
b b 1 b a a 1 a b a rel
m 1 m 1 v 1 j r n r I n r n r I n
ˆ ˆ ˆ ˆ ) (
We know that and
Impulse Equations
Impulse magnitude is given by: The actual impulse vector is simply This is applied to the objects as follows:
n J ˆ j
m J v J p
) ( ) (
1
J r I ω J r L
IMPULSE
t
Linear momentum Angular momentum
b b 1 b a a 1 a b a rel
m 1 m 1 v 1 j r n r I n r n r I n
ˆ ˆ ˆ ˆ ) (
Collision Impulse Magnitude
Where the variables come from
Constants RB State variables Derived values Contact variables p is the contact point Associated with a contact direction n
b b 1 b a a 1 a b a rel
m 1 m 1 v 1 j r n r I n r n r I n
ˆ ˆ ˆ ˆ ) (
Collision Response
- We now have a method for 3D Collision response using
impulses
- Given this simple equation we can calculate the
instantaneous change in Rigid Body state quite straightforwardly
- Response is easy but there are some issues to deal with
– Contact Modelling – getting accurate collision points+normals, manifolds etc is still expensive – Interpenetrations often occur and can cause lack of robustness
Non-Interpenetration
Due to discrete timesteps the instant of collision (or point
- f discontinuity) is not obvious.
In most cases collision detection returns the fact that
- bjects have interpenetrated at time t0+t
time = t0+t time = t0
For accurate calculations we need the exact collision time – or at least correct within a certain threshold e
time = tC
Backtracking
Step backwards in simulation time and redo collision detection e.g. Timestep Bisection: a useful (if not reasonable) guess might be t0+t/2 This process is repeated until we achieve a result under some threshold accuracy Some collision detection approaches attempt to analytically calculate tC ... This can be quite expensive
time = t0+t time = t0+t/2+ t/4 time = t0 time = t0+t/2 a.k.a. Retroactive Detection
Adaptive Timesteps
Reduces wasted computation encountered in bisection by pre- emptively reducing timesteps A conservative approximation is taken as to when discontinuity
- ccurs and simulation
takes place to this point As discontiuity gets closer increasingly small steps are taken
time = t0
t0 + t t0 + 2t …+ 2t + t /2 …+ t/4 …+ t/8
Timestep is halved when the spacetime- bound suggests that the object will interpenetrate in the next step a.k.a. Conservative advancement
Timewarp
[Mirtich 2000] Main problem with previous methods are that they deal with the synchronous evolution of the entire scene Asynchronous processing of individual interactions can greatly improve performance Basic idea is to rollback to time of discontinuity but only for relevant
- bjects that have penetrated and for
- bjects dependent on these
Similar to having several different simulation processes communicating at key points (collisions)
[Mirtich 2000] Brian Mirtich - Timewarp Rigid Body Simulation, ACM Siggraph 2000
Required Reading
- Chris Hecker has a few Gamasutra Articles on the
topic that are relatively easy reading:
– In particular, “Physics Part 4 – The 3rd Dimension” – Available http://chrishecker.com/Rigid_Body_Dynamics
- Baraff Witkin Kass Lecture 2001
– Rigid Body Dynamics Notes – Collision and Contact
Other Useful References
Erik Neumann’s MyPhysics Lab: http://www.myphysicslab.com/collision.html
Papers Referenced in this Lecture
[Moore & Wilhelms] Collision Detection and Response [Mirtich] Timewarp Rigid Body Simulation (http://www.merl.com/papers/docs/TR2000-17.pdf) [Mirtich] Impulse based Rigid Body Simulation
Final Project - Option
You may opt-out of your proposed animation/physics proposal by extending on your rigid body physics engine N.B. This won’t necessarily be easier You must notify me by March 12th that you wish to switch to this option
Rigid body engine (part 1 - basic requirements)
Implement a Rigid Body Engine for Non-convex Meshes, should include as many of the following as possible
Complete working Multi-phase Collision Detection: GJK, BVH , Sweep and Prune Optimized for performance where possible Should support polyhedra, particles, sphere, groundplane File loader for display (mesh + texture) and/or dynamics proxy Center of Mass & Inertial Tensor computation (may be approximate) Non-Euler Integration Quaternions for rotation Visualisation Mode (exposing some of the intermediate variables) Scene definition not hard coded
Rigid body engine (part 2 – extensions)
KEY Investigative Objectives (at least one of the following to be encorporated):
Multiple contact collision response or reasonably stable sequential response [] Constraints [] Friction [] Space-time Bounds / Continuous Collision detection Other equivalent (please specify) Demo + Youtube Video, Proper Documentation and Comments, 4 page report detailing extensions to lab work in weeks 1-7
Multiple point contact resolution
How to deal with multiple contacts? Many Physics tutorials tend to gloss over this point but it is quite an important one. Some Possible Solutions:
Average contact points and solve single net impulse
Not robust - only valid for convex regions
Micro-impulses: approximate an earliest collision and solve each point independently
not a complete solution (we’ll see why soon) and doesn’t guarantee robustness however you could get away with it
Account for influences of each point and solve simultaneously
Multiple Colliding Contacts
Single point collisions between two bodies, A & B At time of collision tc : pA(tc) = pB(tc) = p For any point i in contact between bodies A and B Our assumption for each contacting point on each body:
pi influences pi+n which influences pi
( ) ( ) ( )
i i
A c B c i c
p t p t p t
C
Multiple contacts
Sequential impulse solution:
Apply impulse at p0
Body moves to the right penetrating into C
Apply impulse at p1
Body moves towards left penetrating into B
Looking at just the linear velocity we require either that…
A must stop A must bounce upwards
Angular velocity:
B C A
p0 p1
B A
p0 p1
B C A
p0 p1
Symmetrical case w=0 A rotates clockwise
Avoiding Interpenetration
Body B must exert a force C on body A at the point of
- contact. Such force must satisfy the following:
1. C acts only at the instant of contact, not before not after 2. C must be a repulsive force. Cannot act like glue between bodies 3. C must prevent the interpenetration of the bodies 4. The system cannot gain kinetic energy from the introduction of this force
Use impulse equation j previously defined j >= 0 at point of contact
j
rel rel
) ( v v
( ) ( )
rel c rel c
v t v t
- Assume coefficient of restitution relates to
each collision point individually
- Bodies may be pushed away from each
- ther by a third more powerful simultaneous
collision
( ) ( )
rel c rel c
v t v t
Rewrite Newton’s restitution law to account for this :
Multiple Contacts
- Newtons law of Restitution for frictionless collisions :
- Doesn’t readily extend to multiple point collisions
- need “looser” assumptions
( ) ( )
rel c rel c
v t v t
OR
Using Reformulate post collision velocity equation to account for simultaneous points of contact Remembering Newton’s third law and substituting gives us relative velocity at point i in the normal direction
1 1 1
( )
j j j i i i
n n j j j j
f n I r f r p p n M
i i i
v p p
r J r I M J v
) (
1
n ˆ f J A
N.B. We’re using the symbol f instead of j for impulse magnitude, to avoid confusion with the subscript j
( ) ( )
rel c rel c
v t v t
Using: and substituting from (1 )
i
i rel i
b v
We get: Or: Which can be expressed as
Aside: Linear Systems of Equations
Often occur in Physics e.g. simultaneous contact LCP, deformable bodies Simultaneous equations of the form: Can be written Ax = b where Outside the scope of this course but if you need to read up on this, see:
“Linear Algebra”, J. Hefferon, available online: http://joshua.smcvt.edu/linearalgebra/
Generic LCP
So Using We have formulated what is known as a Linear Complementarity Problem (LCP) Formally stated:
( ) ( )
rel c rel c
v t v t
( )
c
f t
( )( ( ) ( ))
c rel c rel c
f t v t v t
Given a known vector b and a known matrix the problem is to find a vector such that
w Af b
f
- r to show that no such vector exists.
So we solve the system The vector f in our case is simply the list of unknown impulse magnitudes f which is to be solved for Last formulation fed into LCP solver and solved for fi Calculated impulse magnitudes then applied to rigid body states to perturb initial non collision motion Note, impulses applied so as to change rigid body momentums
Simultaneous Contact Resolution
Collision Detection: Calculate all contact points for current rigid body state Contact points and rigid body states are used to compute the matrix A and vector d LCP Solver computes f and d. We are guaranteed no- interpenetration since d>= 0 Post-impulse velocities calculated from f and normal vectors at collision points ODE solver computes new positions and orientations of rigid bodies
Simultaneous Contact Resolution
Disadvantages:
Specialised LCP solver needed Addition of friction causes A matrix to become non Positive Semi Definite (PSD) (a solution for the LCP may not exist)
Advantages:
For frictionless contacts/collisions the A matrix is always PSD so a solution will always exists and is solvable within theoretical polynomial time LCPs are closely related to Quadratic Programming (QP) problems so it is possible to solve a PSD LCP with well established QP methods
LCP Solvers
LCP is a well studied problem for discontinuous relationship between two variables e.g. contact conditions between rigid bodies. Four main solutions:
Newton Methods
Quadratic convergence, O(n3) work per iteration
Interior point methods
Quadratic convergence
Direct methods (pivoting methods)
Work per iteration O(n2) Lemke O(n3)
Iterative methods
Iterative Solvers
Current trend is to use iterative methods (a.k.a projection methods) for solving LCPs
Used in Novodex, ODE, IO Interactive
trade off between accuracy and speed
Linear convergence Work per iteration O(n), if upper bound is placed on iterations Worse convergence but can 5-10 iterations
Strategy for LCPs: From Ax = b introduce a splitting
A = M – N so that we have (M-N) x = b and formulate as
Where the projection operator written (x)+ :
) (
1 1 k k
Nx b M x
) ), , max(min(
j lo hi j j
j
x x x x
See [Murty]
LCP Solvers
PATH from CPNET by Michael Ferris is robust Newton based Solver:
http://www.cs.wisc.edu/cpnet/cpnetsoftware/
David Eberley “Game Physics” has an LCP solver implementation based on Lemke’s algorithm (pivoting method) ODE contains a solver using Successive-Order-Relaxation LCP Solver, Dantzig Pivoting algorithm and Conjugate Gradient
Related problem: Contact Forces
Forces between objects in physical contact but not colliding i.e. vREL >= 0 Resting contact: objects touching but not moving towards each other Accelerating towards each
- ther but kept in check by
an equal and opposite reaction force
Contact Forces
To avoid interpenetration when acceleration of body A is into body B, B must exert a contact force on Body A:
C must prevent interpenetration of the bodies C must be a repulsive force – cannot act like glue between
- bjects
C must become zero when bodies separate
Once again various solutions:
Springs at contacts, Impulses (microimpulses), Analytical solution, LCP
References
Katta G. Murty. Linear Complementarity, Linear and Nonlinear Programming. Helderman-Verlag, 1988.
Web version: http://ioe.engin.umich.edu/people/fac/books/murty/linear_complementarity_webbook/
Richard W. Cottle, Jong-Shi Pang, and Richard E. Stone. The Linear Complementarity Problem. Academic Press, Inc., 1992. David Eberly “Game Physics” Chapter 7 Linear Complementarity and Mathematical Programming Chris Hecker, “The Mixed Linear Complementarity Problem:
http://chrishecker.com/The_Mixed_Linear_Complementarity_Problem
Thanh Giang “Complementarity Based Multiple Point Collision Resolution”
http://isg.cs.tcd.ie/cosulliv/Pubs/GiangEgirl03.pdf
Kenny Erleben. Stable, Robust, and Versatile Multibody Dynamics Animation. PhD thesis, Department of Computer Science, University of Copenhagen (DIKU), Universitetsparken 1, DK-2100 Copenhagen, Denmark, March 2005. ftp://ftp.diku.dk/diku/image/publications/erleben.050401.pdf. Contact Online Demo and tutorial
http://www.myphysicslab.com/contact.html