Skip to content
Physical AI
All experiments

Falling ball with adjustable gravity

Constant acceleration under gravity, the exchange between potential and kinetic energy, and how a coefficient of restitution turns an impact into energy loss.

Loading simulation…

What it demonstrates

Constant acceleration under gravity, the exchange between potential and kinetic energy, and how a coefficient of restitution turns an impact into energy loss.

How it works

The ball is a point mass. Every 1 ms the simulator applies gravity with semi-implicit Euler: velocity first, then position with the new velocity. Before the first bounce the computed height differs from the exact y₀ − ½gt² by exactly ½·g·t·Δt, about 5 mm after one second on Earth.

When the ball passes below the floor, the penetration is removed and the downward velocity is replaced by e times the impact speed, pointing up. This is an impulse-based contact. The readout shows the impulse divided by the step length as an average force. Once the rebound speed drops below 5 cm/s, the ball is treated as resting and the floor supplies exactly m·g.

Adjustable parameters

  • Gravity g (0–25 m/s², presets Moon 1.62, Mars 3.71, Earth 9.81, Jupiter 24.79)
  • Coefficient of restitution e (0–1)
  • Drop height (0.5–20 m)
  • Mass (0.1–5 kg): affects energy and force, not the trajectory

Known limitations

  • No air drag. A real ball in air reaches a terminal velocity.
  • The ball is a point. Spin, deformation and rolling are not modelled.
  • Removing the penetration by clamping the position slightly changes energy at each bounce.

Equations

y¨=−g,y(t)=y0−12gt2\ddot y = -g, \qquad y(t) = y_0 - \tfrac12 g t^2
E=12mv2+mgyE = \tfrac12 m v^2 + m g y
v+=−e v−,hn+1=e2hnv^+ = -e\,v^-, \qquad h_{n+1} = e^2 h_n
vk+1=vk−g Δt,yk+1=yk+vk+1Δtv_{k+1} = v_k - g\,\Delta t, \quad y_{k+1} = y_k + v_{k+1}\Delta t

Core update rule

// lib/sim/ch02-mechanics.ts — stepBall
v -= g * dt;               // semi-implicit Euler
y += v * dt;
if (y < 0) {
  y = 0;                    // remove penetration
  if (v < 0) {
    const vin = -v;
    v = e * vin;            // restitution
    contactForce = m * (1 + e) * vin / dt;
    if (v < REST_SPEED) { v = 0; resting = true; }
  }
}

Explained in Chapter 2: Physics Engines