skip to content

How do you derive the normal impulse that resolves a collision between two rotating rigid bodies at a single contact point?

level: middleimportance: must knowfreq 50%

answer

  1. relative velocity of contact points
  2. normal component, sign tells approach
  3. linear plus rotational inverse mass
  4. -(1 + e) over effective mass

basics

~20 s

Require the relative normal velocity of the two contact points to become -e times its old value and solve for one scalar impulse: j = -(1 + e) * vn / K, with K the inverse effective mass including rotation.

solid answer

~40 s

Take the normal `n` from A to B and lever arms `rA`, `rB` from each centre of mass to the contact. The relative point velocity is `vRel = (vB + cross(wB, rB)) - (vA + cross(wA, rA))` and `vn = dot(vRel, n)`, negative when approaching. Apply `+j*n` to B and `-j*n` to A: each body's velocity changes by `j*n/m` and its angular velocity by `I^-1 * cross(r, j*n)`, so `vn` changes by `j*K` with `K = 1/mA + 1/mB + dot(cross(rA,n), IA^-1*cross(rA,n)) + dot(cross(rB,n), IB^-1*cross(rB,n))`. Setting `vn + j*K = -e*vn` gives `j = -(1 + e)*vn / K`, positive, applied only when `vn < 0`. A static body contributes zero inverse mass and inertia. Friction repeats this along the tangent and clamps the result to `mu*j`.

code

pseudocode · 35 lines
pseudocode
// n is unit length and points from body A to body B
function resolveContact(A, B, p, n, e, mu):
    rA = p - A.centerOfMass
    rB = p - B.centerOfMass
    vRel = (B.v + cross(B.w, rB)) - (A.v + cross(A.w, rA))
    vn = dot(vRel, n)
    if vn >= 0:
        return                       // separating or resting: no impulse
    rnA = cross(rA, n)
    rnB = cross(rB, n)
    K = A.invMass + B.invMass
      + dot(rnA, A.invInertiaWorld * rnA)
      + dot(rnB, B.invInertiaWorld * rnB)
    j = -(1 + e) * vn / K            // positive: contacts only push
    applyImpulse(A, B, rA, rB, j * n)

    // friction, from the velocity after the normal impulse
    vRel = (B.v + cross(B.w, rB)) - (A.v + cross(A.w, rA))
    vt = vRel - dot(vRel, n) * n
    if length(vt) < epsilon:
        return
    t = vt / length(vt)
    rtA = cross(rA, t)
    rtB = cross(rB, t)
    Kt = A.invMass + B.invMass
       + dot(rtA, A.invInertiaWorld * rtA)
       + dot(rtB, B.invInertiaWorld * rtB)
    jt = clamp(-dot(vRel, t) / Kt, -mu * j, mu * j)
    applyImpulse(A, B, rA, rB, jt * t)

function applyImpulse(A, B, rA, rB, P):
    A.v = A.v - P * A.invMass
    A.w = A.w - A.invInertiaWorld * cross(rA, P)
    B.v = B.v + P * B.invMass
    B.w = B.w + B.invInertiaWorld * cross(rB, P)

go deeper

for a junior

Recall that the contact point's velocity includes rotation, v plus w cross r, and that the impulse acts equally and oppositely along the contact normal.

for a middle

Derive j = -(1 + e) * vn / K out loud, keeping the normal's direction consistent and explaining where each rotational term in K comes from.

for a senior

Show you have debugged this in code: sign flips, impulses on separating contacts, body-space inertia, and friction clamped to weight instead of the normal impulse.

for a principal

Explain why this single-shot form is only the inner step of a real solver and what a team gains by building and testing that step in isolation first.

## Conventions first A collision impulse derivation is all signs, so fix the conventions before writing anything: - Two bodies **A** and **B** touch at a world-space point `p`. - The unit contact normal `n` points **from A to B**. - `rA = p - cA` and `rB = p - cB` are the lever arms from each body's centre of mass to the contact point. - Each body has linear velocity `v`, angular velocity `w`, mass `m` and a world-space inertia tensor `I`. Solvers store the inverses, `1/m` and `I^-1`, because a static body is then just zeros. - An **impulse** `P` is a force integrated over an instant: it changes velocity at once, `v += P / m`, and changes angular velocity by `I^-1 * cross(r, P)` when applied at lever arm `r`. ## The velocity of a contact point A point on a spinning body moves with the body and with its rotation: `vPoint = v + cross(w, r)`. The **relative velocity** at the contact is B's point velocity minus A's: `vRel = (vB + cross(wB, rB)) - (vA + cross(wA, rA))` and its normal component is `vn = dot(vRel, n)`. With `n` pointing from A to B, a negative `vn` means B's point is moving back toward A: the bodies are **approaching**. A positive `vn` means they already separate, and the solver must do nothing. ## Applying one impulse along the normal The collision is resolved with a single scalar `j` applied along the normal: `+j * n` on B and `-j * n` on A (equal and opposite). The derivation is four steps: 1. B's linear velocity changes by `j * n / mB`, and its angular velocity by `IB^-1 * cross(rB, j * n)`. 2. A's changes are the same with the opposite sign and A's own mass properties. 3. Substitute into `vn` and collect terms. The normal relative speed changes by `j * K`, where `K = 1/mA + 1/mB + dot(cross(rA, n), IA^-1 * cross(rA, n)) + dot(cross(rB, n), IB^-1 * cross(rB, n))` The two rotational terms come from the identity `dot(n, cross(u, r)) = dot(u, cross(r, n))`. 4. `K` is the **inverse effective mass** of the contact along `n`; `1/K` is how heavy the pair feels when pushed at that point in that direction. The rotational terms are never negative, so hitting a body off-centre never makes it harder to push at that point, and makes it **easier** whenever the line of the impulse misses the centre of mass: part of the impulse goes into spin. When the line of the impulse passes through the centre of mass, `cross(r, n)` is zero and only the linear terms remain. ## Solving for the impulse The bounce rule says the separating speed after the impulse is `-e * vn`, with `e` the restitution: `vn + j * K = -e * vn`, so `j = -(1 + e) * vn / K`. Because `vn < 0` for approaching bodies, `j` is positive: contacts only ever **push**. Check the limits: - `e = 0` gives `j = -vn / K`, which exactly cancels the approach speed. - A **static** body has `1/m = 0` and `I^-1 = 0`, so it adds nothing to `K` and takes no velocity change. - Two equal spheres meeting head-on with `e = 1` exchange their normal velocities, as the textbook elastic collision predicts. The inertia tensor must be the **world-space** inverse inertia for the body's current orientation; the body model owns how that is built, and using the body-space tensor here makes off-centre hits spin about the wrong axes once the body has turned. ## Friction along the tangent Friction uses the same machinery in the tangent direction. Take the tangential part of the relative velocity after the normal impulse, `vt = vRel - dot(vRel, n) * n`, normalise it to `t`, compute `Kt` with `t` in place of `n`, and solve for the impulse that would stop the sliding: `jt = -dot(vRel, t) / Kt`. Coulomb's law then clamps it: | friction shape | clamp | trade-off | |---|---|---| | cone | the full tangent impulse to length `<= mu * j` | isotropic, slightly costlier | | pyramid | each of two tangent directions to `[-mu * j, mu * j]` | cheap and linear, up to about `1.41 * mu` along diagonals | ## Mistakes that show up in code - Flipping the normal's direction in one place and not the other, which turns a push into a pull. - Applying the impulse when `vn > 0`, glueing separating bodies together. - Forgetting the rotational terms in `K`, so off-centre hits are far too weak or far too strong. - Clamping friction against a fixed weight instead of the normal impulse just computed. This single-shot form handles one isolated contact; with many touching contacts the same formula becomes the inner step of an iterative solver.

  • What happens to the impulse if both lever arms are parallel to the normal?
    Then `cross(rA, n)` and `cross(rB, n)` are zero, the rotational terms vanish and `K = 1/mA + 1/mB`. The impulse passes through both centres of mass, so it changes only linear velocities and creates no spin, exactly as for two point masses.
  • Why does a solver store inverse mass and inverse inertia rather than mass and inertia?
    The impulse formula only ever needs the inverses, and a static or infinitely heavy body is then simply zeros: it adds nothing to `K` and receives no velocity change, with no division by infinity and no special case in the inner loop.
  • Two equal spheres collide head-on with restitution 1. What does the formula predict?
    With equal masses and no rotation, `K = 2/m`, so `j = -2*vn / (2/m) = -m*vn`. Each sphere's normal velocity changes by the full approach speed, in opposite directions, which swaps their normal velocities: the textbook elastic exchange.

  • The impulse should be applied even when the bodies are already separating.
  • Rotation can be ignored when computing a contact impulse between boxes.
  • A static floor needs its own large mass value in the impulse formula.
  • The body-space inertia tensor can be used directly in the impulse formula.
  • A negative impulse along the normal is fine; it just pulls the bodies together.