Home / Science / Physics / Classical mechanics / Two-body orbit sandboxTool #903

Two-body orbit simulator: masses and velocities to an animated orbit, period, eccentricity, energy and angular momentum

Give two bodies a mass, a starting position and a velocity and watch them orbit their centre of mass. Get the shape, eccentricity, semi-major axis, closest and farthest approach and period, with an independent numerical check that energy and angular momentum are conserved.

Keep it one tap away for everyday use.

Bookmark Two-body orbit sandbox?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Bodies
  2. Orbit
  3. Elements
  4. Checks
Nothing is uploadedWorks offline once open

Two bodies

Body 1
Body 2

Give each body's mass, starting position and velocity in a flat plane. Only the difference between the two matters for the shape of the orbit; the rest moves the centre of mass, which the picture holds still. GM of the Sun (1.32712440018 × 10²⁰ m³/s²) and of the Earth (3.986004418 × 10¹⁴ m³/s²) are standard values; the presets are rounded or made up.

The orbit

Checks

The motion is the exact solution of the two-body problem (Kepler's laws, solved with universal variables, so ellipses, parabolas and hyperbolas all work). As an independent check, the page also integrates both bodies directly with fourth-order Runge-Kutta and reports how well energy and angular momentum are kept and how close the two answers end up. Point masses only. For study and planning, not a substitute for professional judgement.

Download

What it does

Two bodies pulling on each other by gravity, and nothing else, is the one orbit problem with an exact answer. Both bodies circle their shared centre of mass, each tracing the same shape (a circle, an ellipse, a parabola or a hyperbola) scaled by the other body’s share of the mass. This sandbox lets you set up any two bodies in a plane and see what they do.

You give each body a mass, a starting position and a velocity. The page shows the orbit animated around the centre of mass and works out the shape and eccentricity, the semi-major axis, the closest and farthest separation, the period (Kepler’s third law), the escape speed, and the orbital energy and angular momentum.

How it checks itself

The motion on screen comes from the exact Kepler solution, written with “universal variables” so the same formula works for bound and unbound orbits. As an independent check, the page also integrates both bodies step by step with Newton’s law of gravity and fourth-order Runge-Kutta, using smaller steps near close approach. The Checks box reports how well that integration keeps the total energy and angular momentum constant, and how far its final positions are from the exact solution. When both are tiny, you can trust the numbers; very close fly-bys show larger drift, which is a property of the integration, not of the exact answer.

How to use it

  1. Pick a preset or type your own numbers (the list switches to Custom).
  2. Pick the units: star scale (Sun masses, AU, km/s, days) or planet scale (Earth masses, km, km/s, hours).
  3. For each body, type its mass, starting x and y, and velocity vx and vy.
  4. Pause, Play and the speed slider control the animation; one orbit (or the fly-by) takes about eight seconds at speed 1.

Worked example

Choose the made-up eccentric binary star: a 1 M☉ star at rest at the origin and a 0.5 M☉ companion 1 AU away moving sideways at 20 km/s. The escape speed there is 51.59 km/s, so they stay bound. The page shows an ellipse with e = 0.699, semi-major axis 0.5884 AU, closest approach 0.1769 AU, farthest 1 AU, and a period of 134.6 days. The heavier star swings around 0.333 of the separation from the centre of mass, the lighter one 0.667. The integration check keeps energy to about 10⁻¹² and the two methods agree. Switch to the Sun and an Earth-like planet and the period becomes 365.1 days with e = 0.000318: almost a circle.

Tips

  • Give a body exactly the escape speed √(2G(m₁+m₂)/r), sideways, to get a parabola; any faster is a hyperbola.
  • The sideways (tangential) part of the relative velocity sets the angular momentum; with none, the bodies would fall straight together, which the page refuses.
  • Moving both bodies by the same velocity changes nothing in the picture: it only moves the centre of mass, which is reported.

FAQ

Why does the heavier body move too? Newton’s third law: the pull is equal and opposite, so both accelerate. The heavy one moves less, in proportion to the mass ratio.

Can I add a third body? Not here. Three bodies have no general exact solution and can be chaotic; this tool keeps to the exactly solvable case.

Are the presets real? The Sun and Earth-like and Earth and Moon-like presets use rounded values; the binaries and the fly-by are made up. It is for study and planning, not a substitute for professional judgement.

Where the numbers come from

  • Two-body problem, reduced mass, orbital energy, angular momentum, eccentricity vector and Kepler's third law: standard classical mechanics.
  • Universal-variable Kepler solution with Stumpff functions: as set out in Curtis, H. D., Orbital Mechanics for Engineering Students, chapter 3 (method only, own code).
  • GM of the Sun 1.32712440018 × 10²⁰ m³/s² and of the Earth 3.986004418 × 10¹⁴ m³/s² (IAU and IERS standard values); 1 AU = 149,597,870,700 m (IAU 2012).
  • Checked against an independent SciPy DOP853 integration (relative tolerance 10⁻¹³) of both bodies for an almost circular, an eccentric and a hyperbolic case, and against closed-form circle, parabola and period results. The presets are rounded or made up.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

Projectile and drag simulator #901 Launch a ball at any speed, angle and height and see its real path through the air: quadratic drag from its size, mass and drag coefficient, a head- or tailwind, the range, highest point, time of flight, landing speed, the best angle for distance and how much the air costs compared with a vacuum. Moment of inertia builder #904 Build a body from simple uniform parts (rod, disc or cylinder, tube, ring, sphere, shell, box, point mass, and holes), place each one relative to the axis, and get the total moment of inertia with every step shown, the radius of gyration, the centre of mass, the moment about it and the spin energy at any rpm. Collision calculator #905 Work out the velocities after two bodies collide, in a line or at a glancing angle, for any coefficient of restitution from perfectly elastic to sticking together. See the momentum and energy before and after, the impulse, a before-and-after momentum diagram, or find e from your own air-track measurements. Lagrangian helper #908 Type the kinetic and potential energy of a system in your own coordinates and get the Lagrangian, the generalised momenta, every Euler-Lagrange equation (simplified, with sin² + cos² = 1), the accelerations or the mass-matrix form, the energy function, and a numerical run that checks energy conservation. Rocket equation and delta-v calculator #46 Enter each stage's dry mass, propellant and Isp and get the delta-v of every stage and the whole rocket, the payload fraction, and how it compares with the delta-v needed for orbit, the Moon or Mars. Exoplanet mass calculator #57 Turn a star's radial velocity wobble into the planet's minimum mass (m sin i), or a planet mass into the wobble it causes; add a transit depth for the radius, density and gravity, with the velocity curve drawn. Orbit transfer calculator #47 Delta-v, burn by burn, and transfer time between two circular orbits around Earth, the Moon, Mars, Jupiter or the Sun, with the target's lead angle, how often launch windows come round, and a bi-elliptic comparison. Radial velocity orbit fitter #64 Paste a star's radial velocities and fit a Keplerian orbit: period, semi-amplitude, eccentricity, periastron, systemic velocity with uncertainties, the mass function and the companion's minimum mass.