Hard Constraints

Collision processing

Contact resolution summary

resolve velocity

$\nu_{s} = (\dot{P_{a}} - \dot{P_{b}}) \cdot \hat{n}$calculate initial separating velocity

if $\nu_{s} > 0$ return; // particles are not colliding

$\nu_{s}' = -c\nu_{s}$ // calculate separating velocity after collision

$\mu_{c} = (\ddot{P_{a}} - \ddot{P_{b}}) \cdot \hat{n} \times t$ // Check velocity build up due to acceleration

$\nu_{s}' = \nu_{s}' + c \mu_{c}$, if $\mu_{c} < 0$ // note $\nu_{s}'$must be >= 0 after removing velocity build up due to acceleration

$\Delta \nu_{s} = \nu_{s}' - \nu_{s}$calculate new separating velocity

if $\sum\frac{1}{m} <= 0$ return // exit if inverse mass is less than zero

$g = \Delta \nu_{s} \times \sum \frac{1}{m}$ // calculate scala impulse

$ G = \hat{n} \times g$ // calculate impulse vector

$ \dot{P_{a}}' = \dot{P_{a}} + \frac{1}{m} G $ // apply impulse for particle a

$ \dot{P_{b}}' = \dot{P_{b}} - \frac{1}{m} G $ // apply impulse for particle b

resolve interpenetration

// TODO implementation

Collision Detection

Resolving Interpenetration

When two object are interpenetrating we will move them apart just enough to separate them.

The total motion of each object is equal to the depth of interpenetration

$\Delta p_{a} + \Delta p_{b} = d$

where $\Delta P_{a}$ is the scalar distance that object a will be moved. The two distances are related to each other according to the ratio of their masses

$m_{a} \Delta p_{a} = m_{b} \Delta p_{b}$

which combines to give

$\Delta p_{a} = \frac{m_{b}}{m_{a} + m_{b}} d$

and

$\Delta p_{b} = \frac{m_{a}}{m_{a} + m_{b}} d$

Combining these with the direction from the contact normal, we get a total change in the vector position of

$\Delta P_{a} = \frac{m_{b}}{m_{a} + m_{b}} dn$

and

$\Delta P_{b} = -\frac{m_{a}}{m_{a} + m_{b}} dn$

where n is the contact normal

Resting Contact

A particle resting on the ground, experiences only one force, gravity. The contact resolver looks at the particle and sees that it has a penetrating velocity of

$\dot{P} = 2 \ddot{P} t$

Applying the collision response, the particle is given a velocity of

$\dot{P}' = c \dot{p} = c 2 \ddot{P} t$

this moves the particle out of interpenetration. it gets an upward velocity, which will carry it off the ground. The upward velocity will only be small, but it may be enough to be noticed

Velocity and the Contact Normal

When we have two objects in resting contact, we are interested in their relative velocity rather than the absolute velocity of either. The two objects might be in resting contact with one another in one direction, but moving across each other in another direction

To cope with this situation, the velocity and acceleration calculations are all performed in the direction of the contact normal only. We first find the velocity in this direction and test to see whether it could have been solely caused by the component of the acceleration in the same direction. If so then the velocity is changed so there is no separating or closing velocity in this direction

$\mu_{c} = (\ddot{P_{a}} - \ddot{P_{b}}) \cdot \hat{n} \times t$

where $\mu_{s}$ is closing velocity due to acceleration and $t$ is time

if we have got a closing velocity due to acceleration build up, remove it from the separating velocity