The following applet simulate formation of a solar system.

There are N particles generated at random distributed location with random distributed velocity.
The constraint is the center of mass is located at the center and the total momentum is zero.
There are gravitation force between particles:
Because this is a 2D simulation), the force is modeled by $\vec{F}=\frac{GMm}{r}\hat{r}$.
When two particles are come too closer, i.e. (distance between center of mass $d < r1+r2$ ,  then perfectly inelastic collision will join two particles into one bigger particle ($M=m_1+m_2$)

Click right triangle at lower right corner to play the simulation.
Click init to set different initial condition.
You can adjust Gravitation constant [b]G[/b] (potential energy) or Total Energy constant ([b]E[/b]: the initial velocity $v$ for each particle is proportional to $\sqrt{E}$ or the initial number of particle [b]N[/b] with sliders.

Click [b]circular[/b] checkbox if you want to have a net angular momentum (counterclockwise).
The slider at the right can be used to adjust the scale for the x-y coordinate system.

Red arrow represents velocity vector for each particle, while blue arrow represents net force acting on each particles (from other particles).

If E is too large (compared to G) so that the total energy is greater than 0, it is not a closed system.
You can increase [b]G[/b] to form a closed system.
However, the kinetic energy will be drcreased (when two particles combined into one - perfect inelastic collision).

Due to conservation of momentum, there is very rare that all particles combined into one big particle located at origin with zero velocity.
The final state consists one or two big stars with few small stars.

You can study many phenomena with this simulation.  Hope you can enjoy it!

/htdocs/ntnujava/ejsuser/2/users/ntnu/fkh/combineparticles_pkg/combineparticles.propertiesFull screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
Download EJS jar file(1344.4kB):double click downloaded file to run it. (14 times by 12 users) , Download EJS source (5 times by 5 users) View EJS source