Homework 1: (Due 2015.10.17 by noon)

Build a particle system representing multiple objects in a 3D world with simple simulated physics.

Use the code example we worked up to in class to begin problem 1 by copying our hw1_starter_code.cpp into your personal repo in a subdirectory named "hw1". (Note that there is also a file hw1_starter_code_heavily_commented.cpp that has huge amounts of verbose commenting to help you understand every line. Please study that file, but base your code on the uncommented version so that any comments you turn in will be your own.) For instance, Frank Zappa (if he were alive and taking 201B) would type this:


    cd /Users/barking-pumpkin/code/mat201b2015
    mkdir student/frank.zappa/hw1
    cp handouts/hw1/hw1_starter_code.cpp student/frank.zappa/hw1/p1.cpp
    cd student/frank.zappa
    git add hw1/p1.cpp
    git commit -m "My very own copy of the starter code"
    git push

Problem 1: hw1/p1.cpp: Detect when the particles collide. (Due 2015.10.11 by noon)

For each pair of particles (A, B), find the distance between A and B. If this distance is less than the sum of the radii of A and B, then A and B are overlapping, in other words, they have collided. Handle this collision according to your aesthetic goals, but don't leave their distance too small. One "obvious" physics-based approach would be to treat it as an elastic collision with conservation of both energy and momentum. Perhaps, take into account how much A and B are colliding. Briefly comment your source code with an explaination of your goals and solutions. How did you handle collisions and why? You must use sound, and the sound must somehow relate to the collisions.

Hint: for testing, to get the starter code to cause more collisions, you will want some combination of more spheres, larger spheres, and faster moving spheres.

Once this is complete to your satisfaction then push it to your repo:


    cd /Users/barking-pumpkin/code/mat201b2015/frank.zappa/hw1
    git add p1.cpp
    git commit -m "Done (at least for now) with problem 1"
    git push

Now make a copy that you will use for problem 2, along these lines:


    cd /Users/barking-pumpkin/code/mat201b2015/frank.zappa/hw1
    cp p1.cpp p2.cpp
    git add p2.cpp
    git commit -m "Starting problem 2 with a copy of my problem 1 solution"
    git push

Problem 2. hw1/p2.cpp: Simulate the n-body problem.

Since we're in 3D, each particle's mass is proportional to the cube of its radius. (You could also optionally add varying densities to your particles.) On each simulated time tick, each pair of particles exert a mutual gravitational force according to Newton's law of universal graviation. You will need to think in terms of the vector form of Newton's law because you need to know not just the amount of force but also the specific direction. (In fact gravity is extremely complicated but we won't worry about that.)

The acceleration on a particle is equal to this force divided by the mass of the particle. You will find that handling collisions becomes important for this simulation because forces get very large when particles are too close to each other which causes them to fly away very quickly. Start with 3 particles, then increase the number. See how many particles your computer can handle. What happens as you reach and exceed this value? Is your particle system pleasing? Is it stable? Should it be? You must use sound, and the sound must relate in some way to the simulation.

Problem 3. hw1/p3.cpp: Make an audiovisual piece.

Organize your particles in time, space, amplitude and frequency (sound and color) according to aesthetic goals of your choosing. Explain your aesthetic goals and how you implemented them. Do something totally aewsome.

Submission Instructions

Create a file hw1/README.md that describes each of your solutions to these problems and answers the questions above.

Turn in (via git push) at least 4 files for this homework: hw1/p1.cpp, hw1/p2.cpp, hw1/p3.cpp, and hw1/README.md. If you added any media files (e.g., .wav, .png, .jpg, .mp3, .mov) then you must push them with git fat push. Also post to the class tumblr with an artifact that exemplifies your response to problem 3.