Re-center a simulation on one body, or on the center of mass.
Recalculates the positions and velocities of every body relative to a chosen body, at every time step. This anchors the camera to that body: it sits at the origin with zero velocity for the whole run, and everything else is described as seen from it. Use it to look at a moon from its planet, or to view a system from its barycenter, where the star’s small wobble becomes visible.
Parameters
Name
Type
Description
Default
sim_data
DataFrame
The output of simulate_system(): a pandas or polars DataFrame with columns id, mass, x, y, z, vx, vy, vz and time. Positions are in meters, velocities in meters per second, masses in kilograms, time in seconds.
required
center_id
str
The id of the body to use as the new origin, or "barycenter" for the mass-weighted center of the whole system. If a body is actually named "barycenter", that body is used.
required
keep_center
bool
Whether to keep the central body’s rows, which are zero in all six state columns. The default True keeps them. False drops them. It has no effect when shifting to the computed barycenter, which is not a body and has no rows.
True
Returns
Name
Type
Description
DataFrame
The same kind of DataFrame it was given (pandas in, pandas out; polars in, polars out), with the same columns. x, y, z (meters) and vx, vy, vz (meters per second) are replaced by their values relative to the new origin. id, mass and time are unchanged. The recorded run settings are carried over.
Raises
Name
Type
Description
ValueError
If center_id is not "barycenter" and no body with that id is in sim_data.
summed over the bodies present at that step. With no outside forces the barycenter moves in a straight line at constant speed, so the barycentric frame is inertial and total momentum is zero in it. A frame centered on a body is not inertial, because the body accelerates. Momentum and angular momentum are not conserved in such a frame.
Examples
Shift a Sun, Earth and Jupiter run to its barycenter. The Sun is no longer at the origin: Jupiter holds it several hundred thousand kilometers away.