# Procedural Generation of Galaxy

I'd like to generate galaxy using seed , with shape changing a bit and positioning X number of stars.

I'd like to make it realistic (as possible). But i have absolutely no idea how i should do that. I'm not talking about procedural content generation , i know a bit about and i can search for it if i need, i talking about formulas to use to generate galaxy and then placing dots (stars) so it can look real.

In my mind i see it this way:

1) place a center

2) generate tentacles (don't know the exact term) (i'd like to set the number of tentacles)

3) place dots randomly around those tentacles.

bonus question : i'd like to move the galaxy ingame (like it move in real) , and i don't get if a rotating would be enough and if the movement is more complex)

• They're called Spiral Arms, while most galaxies are spirals (about 3/4) there are other shapes to consider. – MichaelHouse Jan 19 '13 at 17:52
• Regarding "realistic", keep in mind that a spiral galaxy can have more than 200 billion stars, as the milky way has about 200-400 billion stars, our neighbor the andromeda galaxy has 1000 billion stars. If you were to pretend it is a flat galaxy and floats were precise enough, you could get away with 2D coordinates, 2 floats, so 8 byte per star for 200 billion stars needs 1.6 Terrabyte. So focus on good looking, rather than realistic :) Depending on what you actually need, a texture would do the job much better – Maik Semder Jan 19 '13 at 18:35
• Somewhat related and certainly inspiring: google's awesome "100,000 stars" visualisation of our milky way galaxy (needs webGL) – Maik Semder Jan 19 '13 at 18:45
• @Maik yes of course I should have said it, I want it look realistic in a graphic way. I do not plan to insert the real number of stars. Just enough to look nice (considering that each stars generated could have planets that I'll use too).a texture is not possible since this will become a interactive map. – eephyne Jan 19 '13 at 18:52
• Keep in mind that even astrophysicists haven't fully understood the physics behind galaxy formation and rotation yet. – Philipp Jan 20 '13 at 14:10

Similar to your algorithm, this is the algorithm I would suggest.

Set your variables. Choose armCount arms, radius radius, spinFactor for spin factor, armR for arm radius, starCount for star count and point center point.

1. Place the armCount arms pointing straight away from a central point point. These should be roughly equidistant around the circumference of the circle (with a radius of radius entered on point) that makes up the galaxy.
2. Divide starCount into roughly equal armCount portions.
3. For each arm place starCount/armCount stars randomly inside the cylinder that follows the arm with a radius of armR. Star placement should be weighted in the following way:
1. More likely to be placed towards the core than towards the arm tip.
2. More likely to be placed closer to the center of the cylinder than the outside of the cylinder.
4. Now you have a galaxy shaped like a star with armCount arms. With more stars at the core and the arms somewhat distinct. Time to rotate. For each star, take its distance from the center and multiply that by spinFactor to get a rotationAmount.
5. Rotate each star by the rotation amount clockwise or counter clockwise around the center point.
6. Marvel at the resulting spiral galaxy.

You could probably combine the rotation and placement steps and just place the start initially at their rotated position. I'd do it in separate steps to start with, just so you can see how things form up without being all twisted up.

Bonus answer: Humans haven't really had the star viewing technology long enough to watch a galaxy rotate, so we don't know exactly how it looks. However, from viewing simulations, it looks like it's spinning at higher speed in the center than the outside. You can try applying the same rotation to each star as you do in step 5. Or you can just slowly rotate the entire galaxy and see how it looks.

• Actually we have observational evidence, that the rotational velocity inside and far outside of the galaxy is pretty much the same, also known as the Galaxy rotation problem. The most accepted explanation right now for the huge discrepancy between the expected and the observed result is Dark Matter. – Maik Semder Jan 19 '13 at 18:59
• OK I just saw the years count in the link you provided. I though it was moving a lot faster! Considering that I'll not simulate rotation. – eephyne Jan 19 '13 at 19:07
• @eephyne Yes, it takes a very long time to rotate. The galactic year of the Milky Way is something like 230 million years. It does spin very fast, it has a very, very long way to go. – MichaelHouse Jan 19 '13 at 19:10
• @MaikSemder Thanks, I'd read that the speeds were not what was expected, but didn't know they were nearly the same. Interesting. – MichaelHouse Jan 19 '13 at 19:11

Here are two articles that may give you some more ideas.

Point cloud galaxy generation in Infinity. (broken link)

• I think the second link has become defunct in the past 3 years. – Pharap Apr 12 '16 at 7:33