Thursday, June 30, 2011

Barnes & Hut orbital simulator

After browsing Reddit one day I discovered a cool to me unknown algorithm, Barnes & Hut. I found a explenation of it here. I got some spare time now because of a flu/fever attack so I thought why not try to make something fun out of it. I setteled on a n-body orbital simulator with collisions. The algorithms where quite easy to jot down in Haskell, but I really struggeled on the visualization. In the end I did it the easy way. Each step, an SVG is created. Then a little imagemagik and ffmpeg magic makes a movie of it. I'm quite happy with the end result but I'd love to get better visualization, maybe OpenGL. If someone has an idea mail me =)

You can get the code from my github.
Here's a video: orbit

Update: I've managed to hack together an OpenGL visualizer. It's not very quick but it works for the purpose of demonstrating. I've also done some optimizations and profiling to get the code to run a bit faster, the updates source is on github.


PS. This post, and the code is written during a fever, so no refunds for eye-strain, errors etc. :P


  1. Wow, very nice. Maybe do a version with the 'GLFW-b'. The game 'boomslang' has a lot of code you might find helpful, too.

  2. Thanks a lot =) I'll take a look at the boomslang game, it probably has input handeling and rendering. If I'm lucky I could just plug in my planets instead of the games bouncing balls!