Algorithm to randomly generate 'spiral galaxy'

Posted on 2008-11-19
Last Modified: 2012-08-14
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?

Question by:Chumad
    LVL 84

    Expert Comment

    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.
    LVL 84

    Accepted Solution

    LVL 4

    Assisted Solution


    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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    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). …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now