Here is a simulation of a galaxy using Newton’s law of universal gravitation. Click here to see a 3D rotatable model of the Milky Way Galaxy.

`(* runtime: 8 seconds *)`

n = 275; G = 1; SeedRandom[0]; image = Table[0, {n}, {n}]; nstar = 500;dt = 0.001; theta = Pi/4; Trot = {{1, 0, 0}, {0, Cos[theta], Sin[theta]}, {0, -Sin[theta], 1}};

stars = Table[r = 0.5 Random[]; theta = 2Pi Random[]; {Trot.{r Cos[theta], r Sin[theta],0.1(2Random[] - 1)Exp[-4r]} + {0, 0, 1}, Sqrt[G/r]{-Sin[theta], Cos[theta], 0}}, {nstar}];

Do[image *= 0.9; stars = Map[({r, v} = #; v -= G r dt/(r.r)^1.5; r += v dt; {x, y, z} = r; {j, i} = Round[n({x, y}/z + 0.5)]; If[0 < i <= n && 0 < j <= n, image[[i, j]] += 0.5/z]; {r, v}) &, stars]; ListDensityPlot[image, Mesh -> False, Frame -> False,PlotRange -> {0, 1}], {50}];

#### Links

- Milky Way and Andromeda Galaxy Collision – amazing simulations by John Dubinski
- Millennium Simulation – interesting video, see also Dark Matter Simulation
- Type Ia Supernova – simulations
- Simulation of Newtonian Gravity – Java applet by Mathew Tizard
- Hyperion Spiral Galaxy Demo – cool-looking but I don’t know how accurate this is
- Colliding Galaxies – fun Java applet, originally by Uli Siegmund
- galaxy – nice-looking Java applet
- Universe Holocube – 100 Megaparsec scale laser-etched crystal cube
- Milky Way Galaxy Holocube – scale laser-etched crystal cube
- Astronomy Picture of the Day – amazing astronomy pictures, some of my favorites are Crab Pulsar, Cat’s Eye Nebula, Eta Carinae, Variable star V838 Monocerotis, and Hourglass Nebula
- Cosmographica – impressive astronomical art gallery by Don Dixon
- Breakthrough Propulsion Physics (BPP) – is warp drive possible?

In fact I’m the author of the “Hyperion Spiral Galaxy Demo”, which I describe in more details here (in french).

Just to explain, my goal was to show why spiral arms appear in galaxies, so it is a purely “geometric” work. It was also intended to be simple enough to work in real time, and to demonstrate some features of the real-time graphics tool Demoniak3D, as Hyperion is called now.

There is a nice applet here which lets you play with a 2D Galaxy to understand the spiral arms : the stars follow more or less “tilted ellipses” trajectories, and the spiral arms come from higher densities of stars where the ellipses are closer to each other.

However, I found no physics explanation for the “tilted ellipses”, and I wonder how to add this effect to a n-body simulation like the fantastic ones you made, Paul.

Another interesting thing to do “one of these days” is to implement a n-body simulation algorithm on a GPU, to make it run in real-time. Some references about this can be found here, in section 3.

I like your website design,……………but, the source code is in the way of (in back of) galactic image, please correct this problem.

I love your website! When are new posts coming?

fabulous!

the simulation was great!!amazing!!

can you please provide me the source code for 2 galaxies colliding in matlab?

i will be thankful to you if you can do so!

is there a way to get this c++ code?

Hi,

probably my video will interest you.

It is wonderful, thanx, look like a hyperbolic tiling

daniel