Separation algorithms were used to position particles with a smooth motion. similar methods were used for the shells and nucleus with slight variations.
Optimizations
In the actual program a Parallel.For loop replaces the first for loop to speed up the calculations.
Each particle loops over all PREVIOUS particles and adds equal opposing forces to each.
move to center
Protons and Neutrons in the nucleus are all controlled by the same separation algorithm.
Every particle in the Nucleus moves towards the center.
This force is normalized and then clamped to it’s own magnitude so the particles slow on approach
move away from others
The particle then checks for overlaps with other particles using the radius distances.
If they are overlapping a small separation force is applied.
Each particle i only checks particles [0 - i] for overlap, removing duplicate overlap checks.
Electron Shell separation
Similar to the Nucleus separation, except overlap uses a calculated distance to maintain the configuration
move to radius
Each particle in the shell moves towards the radius distance away from the center.
Using .sqrMagnitude speeds up the calculation and also creates much larger forces the further away the electron is.
move to orbit
The diffRadius vector between the particle and center is rotated 90 degrees to become tangent to the circle.
This can then be used to apply a small orbital force to the particle.
move to Z=0
Because these particles are moving in 3D space but rotate around a 2D circle a small force is applied to get them aligned on z = 0
move away from others
Finally, the same method for separation as the Nucleus is used.
seperationDistance = 2 * Radius * Mathf.Sin(Mathf.PI / ElectronCount); is used as an overlap radius to evenly distribute particles around the circle.