somebodyelse said:
Why the relatively flat spiral galaxy. I know that not all of galaxies are flat spirals but one would think that a relatively flat spiral galaxy should be a statistical anomaly.
For a similar reason to why the solar system is flat. When the initial rotation of the collapsing cloud of particles gets amplified due to the conservation of angular momentum, it prevents particles from clumping too close to the axis of rotation. But nothing prevents them from clumping in the plane perpendicular to that axis.
A test particle in a cloud with some initial rotation will get attracted to the highest concentration of mass (the centre), but while the component of gravitational force in the direction of the rotational axis is affected by centrifugal force, eventually stopping further motion in that direction, there is no such limitation in the direction parallel to the axis - the particle falls towards the rotating plane, passes it and falls back in. As it does so, frictional interactions tend to dampen oscillations, promoting a flat spinning disc shape.
A picture is worth a thousand words, but an interactive program is worth even more. See here:
https://www.khanacademy.org/computer-programming/challenge-modeling-accretion-disks/1180451277
The program visualises some of the above. It does not include any damping interactions apart from some basic collisions, so the oscillations never fully stop. The initial collapse before particles get depleted clearly shows the tendency to form a disc, though.
Try playing with the initial values. You can remove clumping, increase particle number, etc.
As with any n-body simulation, it can get a bit resource intensive. Adding enough particles will grind it to a halt even on the fastest machines.
As long as the formation is from a spinning cloud of matter, a flat disc shape is natural. Elliptical galaxies are thought to be the result of subsequent collisions between spiral galaxies. I suspect given enough time, the ellipticals will flatten again.