• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2547
  • Last Modified:

Algorithm to randomly generate 'spiral galaxy'

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?

  • 2
2 Solutions
ChumadAuthor Commented:
Ok, so those seem to be how nature generates the galaxy. I want ideas on how I can programmatically generate one.

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.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now