skip to content

How is a hinge joint, such as a door on its frame, expressed as constraints and solved by an impulse-based rigid-body solver?

level: middleimportance: should knowfreq 40%

answer

  1. six freedoms, keep one
  2. anchors coincide plus axes aligned
  3. Jacobian row and effective mass
  4. equalities unclamped, limits clamped

basics

~20 s

A hinge pins a door point to a frame point (three equations) and keeps their hinge axes aligned (two more), leaving one rotation. The solver applies unclamped impulses zeroing each constraint's velocity error; limits and motors add clamped rows.

solid answer

~50 s

A free body has six degrees of freedom; a hinge removes five. Three rows make the door's world anchor coincide with the frame's, `(cB + rB) - (cA + rA) = 0`, which alone is a ball-and-socket. Two more require the frame's axis `a` to stay perpendicular to two door vectors `b1`, `b2` that are perpendicular to the door's axis, which leaves only spin about the hinge. Differentiated, each row reads `J * v = 0`; the solver computes `lambda = -(J * v + bias) / (J * M^-1 * J^T)` and applies `M^-1 * J^T * lambda`, the same machinery as a contact. Unlike a contact, these impulses stay **unclamped**, because a joint must pull as well as push. A swing limit is an inequality row clamped one way, a door closer is a motor row with a capped impulse, and a position bias corrects the drift.

go deeper

for a junior

Recall the joint types by what they leave free: a ball-and-socket keeps three rotations, a hinge one rotation, a slider one translation, and a weld nothing.

for a middle

Explain how a hinge's five constraint rows are built, why their impulses are unclamped, and how limits and motors become clamped rows in the same solver loop.

for a senior

Diagnose a sagging, wobbling or exploding jointed object: drift and its position correction, mass ratios along a chain, and limits implemented as teleports.

for a principal

Weigh how much joint accuracy a game needs, such as doors and vehicles versus ragdolls, against iterations, position passes and the cost of an exact block solve.

## Degrees of freedom A free rigid body in 3D has **six degrees of freedom**: three translations and three rotations. A **joint** removes some of them by imposing **constraints**, each an equation the two bodies' positions and orientations must satisfy. A door on a frame should keep exactly one freedom: rotation about the hinge axis. | joint | constraints | freedoms left | |---|---|---| | ball-and-socket | 3 (anchors coincide) | 3 rotations | | hinge | 5 (anchors coincide, axes aligned) | 1 rotation about the axis | | slider | 5 (two translations, three rotations) | 1 translation along the axis | | fixed (weld) | 6 | none | ## Writing the hinge as constraints Let body A be the frame (often static) and body B the door. Each has a local anchor point and a local hinge axis, transformed to world space every step. 1. **Ball-and-socket part** (3 equations): the door's world anchor must equal the frame's world anchor, `C = (cB + rB) - (cA + rA) = 0`, where `r` is the anchor offset from each centre of mass. 2. **Axis alignment** (2 equations): take the frame's world axis `a` and two unit vectors `b1`, `b2` on the door that are perpendicular to the door's own axis. Require `dot(a, b1) = 0` and `dot(a, b2) = 0`. Then `a` is perpendicular to both, so it is parallel to the door's axis and only spin about it remains. ## From positions to velocities An impulse solver works on velocities, so each constraint is differentiated: - the anchor rows become `vB + cross(wB, rB) - vA - cross(wA, rA) = 0`, the same relative point velocity a contact uses; - each alignment row becomes `dot(cross(a, b), wA - wB) = 0`, which forbids relative spin about an axis perpendicular to the hinge. Every row has the form `J * v = 0`, where `v` stacks both bodies' linear and angular velocities and the row `J` is the **Jacobian**. The impulse along a row is `lambda = -(J * v + bias) / (J * M^-1 * J^T)`, applied to the bodies as `M^-1 * J^T * lambda`, where `bias` is `beta / h` times the row's position error. The denominator is the inverse effective mass, exactly like the `K` of a contact; the anchor rows are often solved together as a 3 by 3 block. ## Equality rows, limits and motors A contact is an **inequality**: it may push but never pull, so its accumulated impulse is clamped to be non-negative. The five hinge rows are **equalities**: the joint must pull as hard as it pushes, so their impulses are left unclamped. The extras on a door are rows with clamps: - a **swing limit**, say the door cannot open past 110 degrees, is an inequality row that is active only when the angle reaches the limit and is clamped to push one way; - a **motor**, such as a door closer, is a row targeting a relative angular velocity about the hinge axis, with its accumulated impulse clamped to a maximum per step so it behaves like a bounded torque; - **joint friction** is a motor targeting zero speed with a small impulse cap. All of these rows go into the same sequential-impulse loop as the contacts, so a door can be pushed by a crate, stopped by its limit and pulled shut by its closer in one solve. ## Why a door sags, wobbles or explodes - **Drift**: the velocity rows hold the joint together only to first order, so anchors separate slowly. A Baumgarte bias or a position-projection pass pulls them back; too strong a bias makes the door twitch. - **Mass ratios**: a heavy door hung through a light intermediate body converges poorly and stretches visibly, as a heavy object on a chain of light links does. - **Too few iterations** leave the hinge visibly soft when something pushes the door hard. - **A limit modelled as a teleport**, snapping the angle back after the step, leaves the door's velocity untouched, so it keeps grinding into the limit; a proper limit row removes the velocity too. The pattern to explain in an interview is that contacts and joints are the same machinery: a Jacobian row, an effective mass, an impulse, and a clamp that differs by row type.

  • Why does a hinged door slowly separate from its frame even though the joint impulses are solved every step?
    The solver enforces the joint at the velocity level, which only holds the anchors together to first order; integrating along straight lines while the anchor moves on an arc opens a small gap each step, and an unconverged solve adds more. A position correction, either a Baumgarte bias or a position-projection pass, is what pulls the anchors back.
  • How does a door closer differ from a swing limit as a constraint row?
    A closer is a motor: it targets a relative angular velocity about the hinge axis and clamps its accumulated impulse to a maximum, so it acts like a bounded torque all the time. A limit is an inequality: inactive until the angle reaches its bound, then clamped to push only away from the bound.

  • A hinge removes only the rotation about its own axis.
  • Joint impulses must be clamped to be non-negative like contact impulses.
  • Snapping the door's angle back after the step is a correct swing limit.
  • Joints need a completely different solver from contacts.
  • Once the velocity rows are solved, the anchors cannot drift apart.