# Does the barycenter of an n-body system remain constant during collisions?

I am developing an n-body simulation software which simulates collisions. Most of these have a stationary frame of reference, meaning that orbiting objects may eventually move off the screen. To combat this issue, I am trying to center the n-body system relative to the system barycenter.

Apart from numerical drift due to limited decimal precision, I think that the motion of the bodies will remain smooth and not move around due to the system being centered on the barycenter, but will there be jumps if objects collide and merge with each other?

Edit: My main concern is that because bodies have radii and are not point masses, collisions will occur near point masses but not exactly at them, meaning that barycenter shift may be unavoidable. What could be done here?

• Yes. On the other hand you can calculate cumulative velocity vector on initialization and then subtract it (once, right after initialization) from every body. Dec 28, 2022 at 19:04
• What happens when your bodies collide? Do they always merge? Or can they bounce, or fragment? Dec 30, 2022 at 6:42
• What is the aim of your software? Is it a near-exact integration of the system that can be used for scientific purposes (several such softwares exist), or is it an approximate integration that can be used as illustration, for example in video games or similar? Dec 30, 2022 at 9:37

Conservation of momentum dictates that if there are no forces external to the system then the barycentre will not be accelerated.

That means the second derivative of its position with respect to time is zero. It may still be moving with constant velocity, but obviously that is also zero in the barycentric frame

• By 'accelerated,' do you mean that the barycenter's position will never move? Intuitively acceleration causes movement but perhaps it could be made a little clearer in your answer. Dec 28, 2022 at 23:11
• @fasterthanlight hmm, ok. Dec 28, 2022 at 23:37

My main concern is that because bodies have radii and are not point masses, collisions will occur near point masses but not exactly at them, meaning that barycenter shift may be unavoidable. What could be done here?

As long as your collision mechanics conserve the position and velocity of the barycenter of the colliding bodies, it will also conserve the position and velocity of the barycenter of the entire system.

Probably the simplest way to achieve this is to simply place the new merged body centered at the barycenter of the original colliding bodies, with mass equal to their total mass and momentum equal to their total net momentum (i.e. with velocity equal to the velocity of the barycenter of the colliding bodies).

An easy way to see this is to observe that, by definition, the position and velocity of the barycenter of a system are simply the weighted averages of the positions and velocities of the bodies in the system, with the weights given by the (inertial) masses of the bodies. And the weighted average in turn is simply a weighted sum divided by the total mass of the system, and the value of the weighted sum does not depend on the order in which the summation is done. So you can take any two (or more) bodies and merge them into one body that has the same total mass, barycenter and net momentum, and it won't change the sums in any way.

Ps. Note that, while this method ensures that your collisions will conserve linear momentum, conserving angular momentum in glancing collisions will require you to also keep track of the rotational angular momentum of your bodies. If you don't, and just treat your bodies as point particles with no intrinsic angular momentum, you'll find that merging two bodies that didn't collide exactly head on will cause some angular momentum to "disappear". (It doesn't actually disappear, of course, but just goes into the rotation of the merged body.)