Unlike the two-body case, there is no gain in simplicity if we would use relative coordinates for the -body system in general. For two bodies, there is only one set of relative coordinates, while there are two sets of particle coordinates, one for each particle. For three bodies, there are three combinations of separations between individual particles, just as there are three sets of particle coordinates. In that case, it is a matter of taste which one one prefers to use. For all higher values of , the number of relative separations is always larger than the number of particles (six versus four for , for example). In conclusion, from onward, it makes more sense to define the positions and velocities with respect to a given coordinate system.
Although not necessary, it is often convenient to use the center of mass system for our orbit calculations. The center of mass is defined in any coordinate system as
where is the total number of particles, and are the mass and the position of particle , and is the total mass of the system. We can interpret the right hand side as a type of lever arm equation. In a one-dimensional system of weights hanging from a beam in the Earth's gravitational field, the left and right parts of the beam will be in equilibrium if we support the beam exactly at the center of mass. The same is true for a two-dimensional plank with masses.
With three dimensions, we have no room left in an extra dimension for external support, but an analogous result still holds: the motion of the center of mass is the same as if the entire mass of the system was concentrated there and acted upon by the resultant of all external forces. See any textbook on classical dynamics for a derivation of this property. In the case of an isolated -body system, there are no external forces, and therefore the center of mass will move in a straight line.
Starting with a given coordinate system, and subtracting the center of mass position vector from all particle positions allows us to construct a representation of the -body system in its c.o.m. system (a short hand for `center of mass'). Subtracting the c.o.m. position is not enough, however. While this causes a momentary centering, it is still quite possible that the -body will start drifting off soon thereafter. To keep the system in place, at least on average, we also have to subtract the velocity of the c.o.m. from all particle velocities. Differentiation of Eq. 5.3 gives:
This shows, incidentally, that the total momentum of all particles is zero in the c.o.m. coordinate system. Since the c.o.m. moves in a straight line, no further corrections are necessary. Throughout this book, when we set up initial conditions for an -body system, we will do so in the c.o.m. of that system.
At the beginning of our code, we see how positions, velocities, and accelerations are now represented by two-dimensional arrays, where the first counter indicates the number of the particle in an -body system, and the second counter the Cartesian coordinate. Note that in C++ array counters start at zero. Therefore, the component of the position of the 3rd particle is not stored in a as one might naively think, but rather in a. In a 3-body system such as the one coded here, the value a is in fact undefined, since it lies outside the memory area assigned to the area; using that value would present a serious bug.