Skip to content
Lesson 11 of 14

Step 1 of 5 · Reading · ~4 min

Read

Collision Response

Rotational Dynamics

Until now a body was a point: forces moved it and nothing else. A real body also spins, and what makes it spin is where a force is applied. After this lesson your program will turn a force at an offset into both a push and a twist, integrate the orientation along with the position, and report the velocity of any point on a spinning body.

Everything linear has an angular twin

LinearAngularMeaning
position porientation theta (radians, counter-clockwise positive)where it is
velocity vangular velocity omegahow fast that changes
force Ftorque tauwhat causes the change
mass mmoment of inertia Iresistance to the change
a = F / malpha = tau / INewton's second law

In 2D rotation happens about a single axis, so theta, omega, tau and I are all plain numbers.

Torque from an off-centre force

A force F applied at offset r from the centre of mass pushes the body (acceleration F / m, exactly as before) and also twists it. The torque is the 2D cross product of the offset and the force:

tau = rx * Fy - ry * Fx

Push through the centre (r = 0) and the torque is zero: pure translation. Push along the line of r (the force is parallel to the offset) and again no twist. Push at right angles far from the centre and the twist is largest. A positive torque turns the body counter-clockwise.

If the force is applied at a point fixed on the body, such as a thruster bolted to a rocket, the offset turns with the body. Store it in the body's own frame as (bx, by) and rotate it into the world each step with the current angle:

rx = bx * cos(theta) - by * sin(theta)
ry = bx * sin(theta) + by * cos(theta)

Where I comes from

I depends on how the mass is spread out: mass far from the centre is hard to spin. About the centre of mass:

ShapeI
Solid disc, radius rm * r^2 / 2
Thin ring, radius rm * r^2
Box w by hm * (w^2 + h^2) / 12

The ring has twice the inertia of the disc of equal mass and radius because all its mass sits at the rim.

The step

Same semi-implicit order as the linear case, with the angular quantities added. Compute everything from the state at the start of the step, then update velocities, then positions with the new velocities:

tau = rx*Fy - ry*Fx          (offset rotated by the current theta)
v     += (F / m) * dt        omega += (tau / I) * dt
p     += v * dt              theta += omega * dt

A mass of 0 or an inertia of 0 means the body cannot be accelerated in that way. Use inverse values (1/m, 1/I, each 0 when the original is 0) and nothing divides by zero. A body with mass but no inertia translates and never spins.

Velocity of a point on the body

Every point on a spinning body moves with the body's velocity plus a swirl around the centre. For the point at world offset (rx, ry) from the centre:

v_point = v + omega x r = ( vx - omega * ry,  vy + omega * rx )

Worked check: a wheel of radius 1 rolling on the ground has v = (3, 0) and omega = -3 (clockwise). The contact point is at r = (0, -1): v_point = (3 - (-3)(-1), 0 + (-3)(0)) = (0, 0). The point touching the ground is at rest, which is what "rolling without slipping" means. Contacts and friction need this number.

Common mistakes

  • Forgetting to rotate the body-frame offset, so a thruster keeps pushing from the same world point while the body turns.
  • Swapping the cross product terms, which reverses the spin direction.
  • Using the already-updated omega when computing the torque or the angle step.
  • Dividing by zero for a static body.
  • Mixing up the inertia formulas of disc, ring and box.

Your exercise

The starter parses the script and prints; you write inertia, step and point_velocity. The most likely mistake is applying the force at an offset that does not turn with the body.

Up nextSleeping & StabilityProduction

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…