public NBodySystem() { bodies = new Body[] {Body.sun(), Body.jupiter(), Body.saturn(), Body.uranus(), Body.neptune()}; double px = 0.0; double py = 0.0; double pz = 0.0; for (int i = 0; i < bodies.length; ++i) { px += bodies[i].vx * bodies[i].mass; py += bodies[i].vy * bodies[i].mass; pz += bodies[i].vz * bodies[i].mass; } bodies[0].offsetMomentum(px, py, pz); }
public Body[] createBodies() { Body[] bodies = new Body[5]; bodies[0] = Body.sun(); bodies[1] = Body.jupiter(); bodies[2] = Body.saturn(); bodies[3] = Body.uranus(); bodies[4] = Body.neptune(); double px = 0.0; double py = 0.0; double pz = 0.0; for (Body b : bodies) { px += b.getVX() * b.getMass(); py += b.getVY() * b.getMass(); pz += b.getVZ() * b.getMass(); } bodies[0].offsetMomentum(px, py, pz); return bodies; }