Solved

# Algorithm to randomly generate 'spiral galaxy'

Posted on 2008-11-19
2,155 Views
I'm trying to come up with an algorithm to randomly generate a spiral galaxy of stars.  Each star will be on a flat 2D plane of x,y coordinates.

What would be my best route to generate this? Is there a type of fractal algorithm I could use somehow? Any thoughts?

Thanks
0

LVL 84

Expert Comment

0

LVL 8

Author Comment

Ok, so those seem to be how nature generates the galaxy. I want ideas on how I can programmatically generate one.
0

LVL 84

Accepted Solution

0

LVL 4

Assisted Solution

see:
http://www.mathematische-basteleien.de/spiral.htm

the equation for the sprial is x(t) = at cos(t), y(t) = at sin(t), where t is the angle between 0 and infinity and a is some constant that you choose.  It would seem you need to determine the maximum angle, and then randomly generate numbers (call the number, t) between 0 and MAXANGLE.  For each angle, t, generated, you plug t into the above equations to get the x and y coordinates of the point on the 2D plane where you will draw the star.  You will want to make sure that your graphical display is set so that the origin is centered on the screen, as I know some have the origin at the bottom left corner of the screen.
0

## Featured Post

### Suggested Solutions

Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …