Solar Simulator

There are some things that occur naturally that we cannot directly observe. Some things occur on a very microscopic level where the elements are just too small for us to observe, such as atoms. Similarly, there are some things that occur on a very grand scale, like our solar system. While we cannot directly observe their behaviors, we do have data on how these entities behave. Given this data, we could create a simulation to allow us to observe something that we previously could not see.


Setup

Create a directory assignment2 under assignments in your cs120 directory. All code for the assignment should be stored in this directory.

cd ~/cs170/assignments
mkdir assignment2
cd assignment2

Details

You are required to write at least 2 classes for this program: Planet and Star. Your program should display one Star, with at least 3 planets orbiting the star.

Full orbital mechanics are fairly complex, but we can simplify things greatly. A planet has some current velocity, which can be described by its x and y components. This current velocity will update the position of the planet at each time step.

The gravitational pull of the Sun will affect the velocity of the planets that orbit it. The force of gravity can be computed using the following equation:

F = G × m1 × m2 / r 2

Where G is the gravitational constant, m1 is the mass of the sun, m2 is the mass of the planet, and r is the distance between the sun and the planet.

The true value of G is 6.67384 × 10-11 N, but that is for astronomical distances. We need to scale that down to the size of our window. I have found that 6.67384 × 10-2 N works pretty well for an 800 by 800 window. You might need to play around with the exponent if you use a bigger or smaller window size. You will also need to scale down the masses of the astronomical objects. I can provide (on an individual basis), some testing data for this portion.

We can assume that this gravitational force is always perpendicular to the true velocity of the planet. Therefore, we just need to use a little trigonometry to decompose this force into x and y components. We then just need to subtract these from the x and y velocities.


Class Structure

Some times, starting on paper is the best decision to make. In this case I truly believe that the more you plan on paper, the better your final result will be. Of course, we have a graphical program again. While that seems like it might cause issues with the start on paper approach, you can design your classes on paper first.

For Monday, January 27th, I want you to turn in (on paper!) a design for your Planet class. You should define what the attributes of the class are going to be, as well as any methods you think you might need.

This is worth 10 points of your assignment grade. It does not sound like a lot, but they should be 10 easy points to get each week. Do not neglect them.


Submission

You are required to submit a tar file to http://cseval.roanoke.edu/. On cseval, there is a link for Assignment 2. You can create a tar file by issuing the following commands:

cd ~/cs170/assignments
tar czvf assignment1.tgz assignment1/

"Hacker" Prompt

  1. Collisions: Once you get enough planets in your solar system, you will probably notice that they start overlapping one another. This is not how the actual physics would behave. Instead, the planets would collide. While the true dynamics of such a collision are much more complex, we can simulate a small portion of it in our simplistic simulator.

    When two planets collide in your simulator, they should merge into a single planet. This planet will have a mass that is the sum of the two planets products. The velocity of the resultant planet should be the vector sum of the two planets velocities.

  2. N-Body Problem: As you probably have noticed, the assignment described above only involves interactions between planets and their associated star. However, in the real solar system planets are affected by more than just their star. Other planets affect the orbital path of each other as well.

    Alter your program so that each planet affects the other planets, as far as their orbits are concerned. How easy is it to get a stable orbit now?

  3. Solar Systems in Motion: In the standard portion of this assignment, stars are completely stationary. This is typically how we view our solar system, but it is not actually the case. The entire solar system is orbiting around the super-massive black hole located at the center of our galaxy.

    Update your program so that if multiple stars are created, they affect the locations of one another. What kind of complex behavior can you discover with this scenario written?


Last modified: Fri Jan 24 09:09:04 EST 2014