I coded an $N$-Body tree algorithm. Now I want to test the code for a particle configuration which represents at the beginning a sphere with radius $R=1$. All $N$ particles are randomly distributed inside the sphere. For the mass I chose $m_i=\frac{1}{N}$.

Now the difficult part to me, the right velocity: I want the sphere to rotate around its own axis in such a way that the sphere neither explodes (centrifugal force > gravitational force) nor implodes (centrifugal force < gravitational force). As a result for large simulation time $T_{MAX}$ I would expect a formation as known from a spiral galaxy.

So, I know what I have to consider, but I do not know how to get the right velocities for such a particle distribution. How should I possibly start? I would really appreciate any help.

  • $\begingroup$ Related: physics.stackexchange.com/q/308100 and physics.stackexchange.com/q/94845 $\endgroup$ – Kyle Kanos Feb 20 '17 at 20:31
  • 2
    $\begingroup$ The answer to Distribution of orbital velocities in a disk galaxy for N-body simulation? is presumably also the answer to this one. $\endgroup$ – DilithiumMatrix Feb 20 '17 at 21:19
  • 1
    $\begingroup$ In an N-body code, a spherical distribution of particles will not settle into a disk. Disks form from gas (hydrodynamic) physics, not newtonian dynamics. An initially spherical distribution would better describe a star-cluster or globular-cluster. KyleKanos' linked answer describes how you can start with a disk however. $\endgroup$ – DilithiumMatrix Feb 20 '17 at 21:21
  • $\begingroup$ @KyleKanos I saw those posts but did not find them very useful. I still do not know how to define $\vec{v}$. I can probably use the following equation $\vec{v}(\phi (r) = \sqrt{\frac{3GM(a^2-\frac{r^2}{3})}{a^3}}$. But how do I get $\vec{v}_x$ and $\vec{v}_y$ from it? $\endgroup$ – Samuel Feb 20 '17 at 21:46
  • $\begingroup$ @Samuel doesn't my second link there say how to obtain the Cartesian coordinates from the spherical in the last few lines? $\endgroup$ – Kyle Kanos Feb 20 '17 at 21:48