# Rendering a Galaxy with the density wave theory

Simulating a galaxy without solving the n-body problem

## Overview

This article explains how to set up a realistically looking spiral galaxy using basic astronomical and physical principles. The scientific background is explained briefly but only to the extend needed to understand the simulation. The article is accompanied by C++ source code for procedural generating of a 2d galaxy with SDL/OpenGL.

Spiral galaxies are amongst the most beautiful observable objects in the night sky. Take for instance the whirlpool galaxy shown in image 1. The picture was taken with the NASA/ESA Hubble space telescope. It's one of my favorite images as it features all the components of a spiral galaxy in great detail. One can see a clear spiral structure with a lot of bright red H-II-regions. In addition the spiral arms show a fine pattern of darker lines which are formed by interstellar gas and dust clouds. The gas and dust clouds provide gas and heavy elements needed to form new stars and planetary systems. Spiral arms are the places where new stars are born.

Pretty as it is it's just an image. How might a rotating galaxy look like? To find out one might use N-Body simulations but they are quite complicated (when done properly) and require more computational time than desirable. What we need is a "shortcut", a way to spare ourself the complexity of calculating the interactions between thousands of stars without oversimplifying the problem. For this simulation the "shortcut" is the density wave theory. It will enable us to render a realistically looking galaxy without taking care of the complex n-body interactions involved in the real world.

### Density Wave theory

The simulation is based on principles laid out in the so called density wave theory. This theory was proposed in the mid 1960s by C.C. Lin and Frank Shu in order to explain the spiral arm structure of galaxies [1]. The information presented in this section is based on the Wikipedia article on density wave theory [2]. Originally, astronomers had the idea that the arms of a spiral galaxy were material. However, if this were the case, then the arms would become more and more tightly wound, since the matter nearer to the center of the galaxy rotates faster than the matter at the edge of the galaxy (see Animation 2). The arms would become indistinguishable from the rest of the galaxy after only a few orbits. This is called the winding problem [3]. Lin and Shu proposed in 1964 that the arms were not material in nature, but instead made up of areas of greater density, similar to a traffic jam on a highway [1]. The cars move through the traffic jam: the density of cars increases in the middle of it. The traffic jam itself, however, does not move (or not a great deal, in comparison to the cars). In the galaxy, stars, gas, dust, and other components move through the density waves, are compressed, and then move out of them.

### Classification of spiral galaxies

In order to classify spiral galaxies a classification scheme was devised by Edwin Hubble in 1936. This classification scheme is still in use today. Hubble distinguished between elliptical galaxies and spiral galaxies. The elliptical galaxies were rated based on their eccentricity and given identifier ranging from E0 to E7 with the eccentricity increasing towards E7. The type S0 is an intermediary form of galaxy that marks the transition to the spiral galaxies. Spiral galaxies were separated into two categories on their own. The spiral galaxies and (Sa bis Sc) and the barred spiral galaxies (SBa bis SBc).

For the rest of this article only spiral galaxies will matter. According to the classification scheme the following observations can be made for the different types of spiral galaxies:

• The spiral arm structure becomes more open from a to c
• The amount of dust and young stars decreases from a to c.
• The round central bulge of the galaxy decreases in size relative to the disc size from a to c.

## Trajectories of the stars in a spiral galaxy

The first problem of modeling a realistically looking galaxy is getting its shape right. One theory for explaining the spiral structure is the density wave theory. It explains the typical spiral arm structure as a result of regions with higher star density caused by slight variations in the orbits of its stars. These regions are not static. Stars will move in and out of them as they orbit the galaxy. The Spiral arms can be modeled by using elliptical orbits that are tilted slightly as their radii grow. Although this is a simplification of the orbits it will serve us well for getting a realistically looking shape of the galaxy. I will use the following simplified assumptions for the orbits in the galaxy:

• The orbits of the stars in the galaxy are ellipses. The galactic center is in the focal point. (1. Law of Kepler)
• Adjacent stars will roughly move into the same direction.
• The orbits are slightly tilted with increasing diameter.

To be this clear: In reality orbits look different! They are not closed like an ellipses but open like a rosette. This difference however would not make a significant difference to the visual appearance of the galaxy. Taking Kepler's first law for approximating the orbits isn't very accurate either because the mass of a galaxy is not concentrated in its center but spread over the disk and bulge areas. However most mass is concentrated in the center so there is some justification for this assumption.

Image 3 shows elliptical orbits which exhibit a slight angular offset in their orientation as their diameter is increasing. Even this simple construction is clearly showing a spiral structure. The spiral arms start in the center of the galaxy and extend to the edge. There is no distinct bulge area visible.

Since observations show that most spiral galaxies have a distinct bulge area the visual model needs to be tweaked to represent this fact properly. The bulge area is often circular in shape and so the overall model should allow such shapes. For this reason the model is extended to always have a round core. The eccentricities than increase towards the bulge-disk boundary (yellow circle in image 4) and from there they again change towards the edge of the galactic disk. Beyond the disc the eccentricities will again decrease until they reach circular shapes at twice the diameter of the galactic disc. This represents a galactic halo but only few stars will be rendered there in the simulation later. (For simplicity Image 4 does omit these orbits as they don't contribute much to the overall shape of the galaxy.)

## Surface brightness distribution of a spiral galaxy

Once the orbits are known the galaxy can be populated with stars. This section will provide some background information on the distribution of stars in a spiral galaxy. It will lead to a model allowing the distribution of the stars in a way similar to what is observable in real galaxies. The basic assumption is that stars should be distributed in such a way that the surface brightness distribution of a real galaxy is matched. The surface brightness distribution of the bulge is similar to those of an elliptical galaxy. It can be estimated using the de Vaucouleurs-law:

$$\nonumber I(R)=I_0 e^{\Big(-\kappa R ^ {\frac{1}{4}}\Big)}$$

with $$I_0$$ being the Central Intensity. According to Freeman [3] the surface brightness distribution of the galactic disc can be described using an exponential law:

$$\nonumber I(R)=I_0 e^{\frac{-R}{R_D}}$$

with $$I_0$$ being the Central intensity and $$R_D$$ a characteristic scale length (Distance in which the intensity drops to 50%). The total surface brightness distribution can be obtained by combining both equations as shown in Image 5. For the modeling of the galaxy it is assumed that the distribution function of the stars is similar to the surface brightness function. Applying such a distribution function to the density wave diagrams shown earlier yields the result shown in image 5 (left). The image begins to look like a galaxy even though the stars are drawn as plain white dots at the moment. The coloring of the galaxy will be discussed later on.

## The color of stars

In the previous section the galaxy and its distribution of stars was discussed. For a realistic rendering it is crucial to apply a realistic coloring scheme as stars in a galaxy can only have specific colors. The color of a star greatly depends on its surface temperature. The underlying physical principle is the so called Black-body radiation.

A realistic color scheme should be restricted to colors which are plausible according to Planck's law. For this model the surface temperature of the stars in the simulated galaxy lies between 3000 and 9000 Kelvin. In reality the surface temperature of a star will be subject change throughout its lifespan as it progresses in its path in the so called Hertzsprung Russell diagram. Calculating the color based on a given temperature is a pretty complex process which i won't discuss here in detail. Instead I will use a program called specrend.c which was written by John Walker [5]. For those interested in the physical background of his program i recommend reading his web site where he explains the algorithm in depth. For all others it will suffice to say that his program computes the RGB values for a given temperature. Image 7 shows the result of applying coloring based on Planck's law to the galaxy shown in Image 5. The exponential increase in star density towards the center is now better visible as star colors differ. However the galaxy as a whole still appears to be consisting of a number of more or less unrelated points. At this point the simulation is already rendered by using approximately 60000 stars. Simply rendering more stars doesn't appear to be viable option due to performance constraints. In reality galaxies consist of billions of stars. Simply rendering more stars won't do the trick. Even in a photographic image of a spiral galaxy, the resolution isn't high enough to display distinct stars (unless they are extraordinary bright). What is visible in images is a kind of nebulae which would turn into distinct stars only if you would be able to zoom in greatly. For this reason the model needs an additional feature representing all those stars which are to small to be seen separately. In addition to the stars, nebulae will be added to the galaxy. When using OpenGL one can use the point sprite extension to get the desired effect. For simplicity the nebulae will be distributed evenly over the galactic disc. The result is shown in Image 8.

Image 8 is already a pretty good approximation of the galaxy but one crucial thing is still missing: H-II regions. If you look carefully at Image 1 you will see an abundance of bright red nebulae distributed across the spiral arms. These nebulae are so called H-II regions, huge intergalactic clouds composed of hydrogen. They are galactic nurseries full of newly born bright hot stars whose emissions make the surrounding hydrogen glow in a characteristic red color. In order to match the appearance of a real galaxy the model also needs H-II regions and they should be located in the spiral arms just like in reality. This will be achieved with a trick, first H-II regions are evenly distributed amongst the galactic disc much like ordinary stars except they are rendered as red nebulae. But in order to restrain their visibility to the spiral arms their rendering size is proportional to the distance of two adjacent density waves with a cutoff size below a certain threshold. As a result they only appear in the spiral arms but move exactly like ordinary stars.

## Rotational curve of a galaxy

Until now the motion of the galaxy was ignored. This section will finally discuss the motion of a galaxy.

Lets look at a galaxies rotation curve. A rotation curve shows how fast the stars and gas components of a galaxy move as a function of their distance from the galactic center. Observations show that the inner part of a galaxy is almost moving like a rigid body. This is causing a steep linear ascent in the rotation curve close to the galactic center. With increasing distance from the center the rotation curve flattens and is almost becoming a constant (Image 10; curve B). Interestingly enough this is a contradiction to models based on the distribution of the visible mass of a galaxy (Image 10; Curve A) that led to the hypothesis of the existence of dark matter. Dark matter is an unknown kind of matter that does not interact with visible matter in any form except by its gravitational force. So its not just dark, it's invisible, virtually undetectable except through its gravitational force. It is in fact so mysterious that various attempts have been made to get rid of the concept of dark matter altogether and explain it's effects by tweaking the law of gravity but so far dark matter is still the most accepted explanation for the observed rotation curves of galaxies.

The only thing left to do is to make sure that the rotation curve is similar to the one displayed in Image 10. The final result is shown in Animation 4. It features a galaxy with two spiral arms and H-II regions. The galaxy is of hubble type Sb.

You might also like: