As to generating a galaxy, I found it very difficult to generate a galaxy of a specific shape. One approach that worked quite well was to use a "probability map" kind of approach.
To get an evenly distributed starmap I'd use the following approach:
1. Select a random position on the map
2. Check if any other star is too close
3. If not, place the star, otherwise go to 1
Repeat until you got enough stars.
Very simple, but usually works just fine. Now, the "probability map" makes this a bit more complicated. For this you need an image file of the shape of the galaxy you want. For example, a 128x128 image with a black background and the galaxy shape in shades of grey and white. Each pixel of the map then represents the probability that a star will be present in the area of the map covered by the pixel (i.e. black pixels = no stars, white pixels = many stars, grey pixels = some stars).
Generating a star map would then rougly go as follows:
1. Select a random position on the map
2. Get a normalized R,G or B value (i.e. 0f to 1f) of the pixel that corresponds to the selected position. We'll call this the "pixel value"
3. If (random.nextFloat() < pixelValue) check for close stars and place the star
Repeat until you got enough stars.
Ofcourse this is not an efficient algorithm at all, but map generators do not need to be. And you'll still need to add space lanes and stuff. But I don't really like wormholes or space lanes anyway (is it a coïncidence that the Master of Orion series went down the drain as soon as space lanes appeared?), so that's not a problem for me
Anyway, using this approach (and some toying with paint.net) it was quite easy to generate all kind of complex galaxy shapes, from clusters to spirals. And it didn't requite too fancy mathematics.
_________________
Researcher & game development hobbyist.
http://www.grunnt.nl