Physics Sandbox Node

The Cosmos Lab

Interactive Newtonian mechanics sandbox simulator to visualize satellite orbital dynamics.

Orbit Mechanics
Click and drag to launch a satellite planet with custom velocity
Satellites: 0
Energy (Specific): -
Orbit Type: -
Eccentricity: -
Central Star Mass ($M$): 5000 kg
Weak gravity Strong gravity
Simulation Orbit Presets:
Physics Mode Options:
Quick Instruction Manual:
  • Drag & Launch: Click and drag anywhere in the canvas to draw a velocity vector. A dashed path prediction line will show you where the planet will go! Release to launch.
  • Quick Circular Launch: Simple click anywhere in the canvas to instantly spawn a planet in a stable circular orbit at that distance.
  • Select Presets: Click preset buttons to quickly load classic setups (e.g. Planet & Moon system).
  • Interactive HUD: Hover your mouse cursor over any active planet to inspect its real-time Specific Orbital Energy, Eccentricity, and Orbit Type.
  • Mutual Gravity (N-Body): Toggle this to enable gravity between planets, causing multi-body chaos, collisions, or nested orbits (moon systems).
  • Kepler's 2nd Law: Enable this to render visual "swept area" wedges for the active planet to verify equal areas are swept in equal time intervals.

How it Works: Physics & Mechanics

This sandbox simulates planetary orbits around a heavy central star using Newtonian mechanics. It runs on a continuous numerical integration loop, calculating gravitational forces and updating position vectors at 60 frames per second.

1. Newton's Law of Universal Gravitation

The gravitational force $\vec{F}$ acting on a satellite of mass $m$ due to a central body of mass $M$ at distance $r$ is:

$$\vec{F} = G \frac{M \cdot m}{r^2} \hat{r}$$

Applying Newton's second law ($F = m \cdot a$), the mass of the satellite cancels out, meaning its acceleration depends solely on the star's mass and distance:

$$a = G \frac{M}{r^2}$$

2. Stable Circular Orbit Preset

For a perfect circular orbit, the centripetal acceleration ($a_c = v^2 / r$) must equal the gravitational acceleration:

$$\frac{v^2}{r} = G \frac{M}{r^2} \implies v = \sqrt{\frac{GM}{r}}$$

When launching a planet, the engine calculates the tangential vector perpendicular to the radial vector and applies this exact velocity magnitude $v$ to establish a stable orbit.

3. Velocity Verlet Integration

The engine utilizes the symplectic Velocity Verlet integrator. Unlike standard Euler, it calculates position first, evaluates new acceleration, and then updates velocity to conserve mechanical energy over long time steps:

// 1. Position step
x_new = x + v * dt + 0.5 * a * dt²

// 2. Acceleration step (gravitational field)
a_new = G * M_sun / r_new²

// 3. Velocity step using average acceleration
v_new = v + 0.5 * (a + a_new) * dt

4. Simulation Model & Code

Assumptions: The central star mass is infinite compared to the satellites, representing a fixed center of mass (the sun does not wobble). Satellite-to-satellite gravitational interactions are set to zero to avoid complex N-body chaotic disruptions.