Friday 1 April 2011

Procedural Galaxy Generation

Where does the time go! I meant to have this blog completed last weekend but it quickly grew into two separate postings (more on that later).

When beginning with this project, I actually started with a top down mentality, my initial research was in creating a galaxy full of stars. Doing so gave me the first major problem that anyone creating on the scale of a galaxy on a computer will have, floating point precision, which I will discuss in another blog sometime soon.

There are many different galaxies but they can be categorized into three categories: elliptical, spiral and irregular. I focused on elliptical and spiral since those are the most common. An elliptical galaxy is really simple to create. All you need to do is generate points inside of a bounding sphere in a logarithmic fashion. Meaning that at the galactic core (center of galaxy) there will be a higher concentration of stars than the outer regions.


More fun and rewarding is creating a spiral galaxy, that is because our own Milky Way galaxy is a spiral galaxy. There are 2 elements to a spiral galaxy. The first is the globular cluster (center of the galaxy) where there is a higher concentration of stars similar to the elliptical galaxy. We create this the same way we created our elliptical galaxy. The second element are spiral arms, I found that using logarithmic spiral is the quickest way to accomplish these spiral arms. More on the Logarithmic Spiral can be found at the excellent Math World website.



How many spirals is up to the creator but I found that between 4-6 works best. Keep in mind that the spiral is not a flat surface but has depth where as the stars closest to the globular cluster vary further from the origin whereas the greatest extents of the arms are closer to the elliptical plane. Keeping in mind that there is a larger concentration of stars at the start of each logarithmic spiral (near the globular cluster) and the density trails off, I actually used a completely linear algorithm for the trailing off of the stars though a logarithmic algorithm would probably work better.



All and all I was very happy with my results. Creating this inspired me to go further but also taught me what I will discuss in the next blog post regarding floating point precision. The galaxy is very big and using a brute force approach can cause many problems.

No comments:

Post a Comment