Gravity Simulation

Each particle has a mass, position, velocity, and acceleration. These depend on the forces acting on the object

Gravitational Force

The force of gravity can be described by the following equation.
`F = (G*m_i*m_j)/r^2`
Where G is a constant, `m_i` is the mass of object i, `m_j` is the mass of object j, and r is the distance between objects i and j.

Relative force of gravity. Force of gravity is proportional to the relative mass. Intuitively, a large mass should pull a small mass but a small mass shouldnt pull a large mass.
Force on mass i due to mass j:
`F_(i,j) = (1-m_i/(m_i+m_j))*(G*m_i*m_j)/r^2`
The net force of gravity on mass i is the sum of all the gravitational forces acting on it.
net `F_i = \sum_{j=1}^n F_(i,j)`
Finally, accounting for resistance the net force is:
net `F_i = F_r + \sum_{j=1}^n F_(i,j)`

Resistance Force

Resistance is proportional to velocity `F_r = k * dx/dt`

Position, Velocity, and Acceleration

Given the net force on object i, we can know its acceleration `(d^2x)/dt^2` given the following relationship:
`F = m * (d^2x)/dt^2`(`F = m * a`)
The velocity of object i at time t is:
`v_t = v_(t-dt) + (d^2x)/dt^2 * dt` (`v ` new` = v ` old ` + a * t`)

Code in Javascript & Python