Collision Resolution
Our Problem Collision detection (supposedly) reported a collision. We want to solve it, i.e. move back the colliding objects apart from each other. In which direction and with what intensity? Momentum, velocity, forces 2
Collision resolution To resolve the collision it is necessary to have: Time of collision: the first instant the collision is detected. Contact point: the point where the colliding objects first touch. Contact normal: a normal to the plane passing through the contact point and oriented in the direction separating the two objects. 3
Computing the exact time (somewhere between t and t + t) of collision is not always feasible We can approximate it by bisection. Repeatedly bisecting the time interval and testing, finding a arbitrary short interval [t 0, t 1 ] for which: The objects do not collide at t 0. The objects collide at t 1. Time of collision Computationally expensive! Usually in games, the frame rate t is small enough to not bother. 4
Contact point and normal To estimate the direction of the collision we use the position of the objects at the frame before the collision Closest points at t t assumed as those with largest depth penetration at t. Needs to store previous positions. Usually done for numerical integration anyway. 5
Collision Resolution We now have a mean to estimate time of collision, contact points and contact normal. We still have to correct the position and orientation of the colliding objects 6
Inelastic collisions energy is not preserved. Objects stop in place, stick together, etc. are easy to implement Backing out or stopping process. Elastic collisions Types of Collisions Energy is fully preserved. e.g. (ideal) billiard balls. More difficult to calculate. Magnitude of resulting velocities 7
Linear velocity Setting: objects A and B, resp. masses m A and m B, and initial velocity v A and v B. Unit collision normal n, and the contact point P n P v A+ v A v B v B+ 8
Instant impulses We can solve the collision by using an impulsebased technique. At collision time we apply an impulse on each object at P in the direction n ( n for one of the object). Pushing the two objects apart. The impulse magnitude: j. Velocity is then changed accordingly from v to v +. n impulse B A P impulse A B v A+ v A v B v B+ 9
Reminder: Impulses The rate of change of the momentum, i.e. a force delivered in an instant: F t = p = m(v t + t v(t)) τ t = L = I(ω t + t ω(t)) Momentum is always conserved: m A v A (t + t) + m B v B (t + t) = m A v A (t) + m B v B (t) And so is energy: E Kt t + t + E P t + t + E Kr t + t = E Kt t + E P t + E Kr (t) + E O 10
Linear velocity By conservation we get: m A v A + j A n = m A v A+ m B v B j B n = m B v B+ And explicitly for the velocities: v A+ = v A + j A m A n v B+ = v B j B m B n 11
Coefficient of Restitution To model the elasticity of a collision we define the coefficient of restitution C R of the collision. It describes the ratio of speeds after and before collision along the collision normal C R = v A+ v B+ n v A v B n C R = 1: ideal elastic collision (E k is conserved) C R < 1: inelastic collision (loss of velocity). C R = 0: the objects stick together. 12
Velocity Correction We also know that the velocities before and after collision relate with the coefficient of restitution C R = v A+ v B+ n v A v B n So we have j A = (1 + C R) v A v B n 1 + 1 m A m B j B = (1 + C R) v A v B n 1 + 1 m A m B 13
Velocity Correction We can finally calculate the outgoing velocities 7.1 v A+ = v A + j A m A n v B+ = v B j B m B n Larger mass difference less velocity change. 14
Angular Velocity When the normal is off the center of rotation of the objects, the collision also produces a rotation of the two objects. n ω A (t) P ω B (t) v A (t) v B (t) 15
Angular velocity Handling rotational collision similarly to linear collision. The impulse factor j is adapted accordingly. If one or both objects are rotating, the rotational velocity is added to the general velocity: v A = v A + ω A r A v B = v B + ω B r B where ω are the angular velocities and r the displacement from the center of rotation to the points of contact. 16
Angular velocity The coefficient of restitution equation is adapted accordingly: C R = v A+ v A v B+ v B n n This coefficient is used for further calculation of the linear velocity through the updated j A and j B 17
Angular velocity By conservation of angular momentum: I A ω A + r A j n = I A ω A+ I B ω B r B (j n) = I B ω B+ And we get: ω A+ = ω A + I A 1 (r A j n ) ω B+ = ω B I B 1 (r B j n ) 18
Angular velocity Generalizing the case of linear, the updated factor j: j = (1 + C R ) v A v B n 1 + 1 + I m A m 1 A r A n r A + I 1 B r B n r B n B 19
Angular velocity With this updated factor j, we calculate the outgoing angular velocities ω A+ = ω A + I A 1 (r A j A n ) ω B+ = ω B I B 1 (r B j B n ) This factor is also used to calculate the outgoing linear velocities (same as linear resolution): v A+ = v A + j A m A n v B+ = v B j B m B n 20
Angular velocity from Linear Velocity Two colliding non-rotating objects can create rotation. Is it creating angular momentum from linear momentum? No! Both momentums are conserved, and are separable entities. Angular momentum is relative to a point and measures the entire system. Though neither object rotates around its COM, the system has angular momentum around the mutual COM. COM 21
The full algorithm: Collision resolution Run collision detection to find contact point(s) and contact normal. Calculate linear and angular velocities at these contact points. Use coefficients of restitution and conservation of momentum to determine the impulses to apply. Solve for velocities using the impulses. 7.2 22
Resting contact Our resolution system is theoretically complete. Some special cases can be handled more efficiently. We can have resting contacts between objects For example, a box colliding with on the floor. the floor theoretically moves down, but is assumed stationary, because of theoretically very large mass. 23
Resting contact In our current framework, a box sitting on the floor may jitter around the surface. 24
Resting contact A resting contact occurs when the relative velocity of the two objects along the normal is null (or smaller than some tolerance). One solution: to artificially reduce the coefficient of restitution when we are in that case. Typically linearly dependent on the relative velocity or directly set to zero. after resolution the two objects will have a null relative velocity the box sticks to the unmoving floor. 25
Friction In practice, there is friction between two objects when in contact. Static friction: relatively stationary. Kinetic friction: moving relatively to each other. Rolling friction: is usually ignored in game physics. We can add the friction force in our previous equations using impulses. 26
Friction The friction acts in the tangential plane of the collision normal and resists the movement t = n v A v B n t n v A v B v B (t) v A (t) where the vectors are normalized 27
Kinetic Friction The velocity equations become: v A+ = v A + j A(n + μ k t) m A v B+ = v B j B(n + μ k t) m B ω A+ = ω A + I A 1 (r A j (n + μ k t) ) ω B+ = ω B I B 1 (r B j (n + μ k t) ) 28
Static Friction For small relative velocity, static friction is used. The friction impulses need to be adjusted. When will objects break off? The tangential direction may be undetermined (collision normal and relative velocity parallel) Alternative techniques should be used. 29
End of Collision resolution Next Soft-body physics