Galactic Gravity Simulations

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}];



8 Responses to “Galactic Gravity Simulations”

  1. January 11, 2008 at 7:02 am

    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.

  2. 2 Scott Houdek(Orion105)
    June 11, 2008 at 8:32 am

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

  3. October 21, 2008 at 9:09 pm

    I love your website! When are new posts coming?

  4. 5 souvik priyam adhya
    May 5, 2009 at 9:54 am

    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!

  5. 6 Samuel
    November 11, 2009 at 2:10 am

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

  6. 7 Jonathan Hilairet
    September 8, 2010 at 2:16 am


    probably my video will interest you.

  7. January 5, 2011 at 10:49 am

    It is wonderful, thanx, look like a hyperbolic tiling


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Welcome !

You will find here some of my favorite hobbies and interests, especially science and art.

I hope you enjoy it!

Subscribe to the RSS feed to stay informed when I publish something new here.

I would love to hear from you! Please feel free to send me an email : bugman123-at-gmail-dot-com


Blog Stats

  • 555,424 hits

%d bloggers like this: