CSCI 1300
Introduction to Computer Science
Homework 3: Orbit Simulation

Due Date

All work must be submitted by 7:50am on Tuesday, Feb 16. Submit the programming work online to http://culearn.colorado.edu. No late work is accepted, so submit what you have before the due date!

Working Alone

You may talk with other students and instructors about the assignments, but you may not look at or copy code written by others. The penalty for violating this code is an F for the entire semester.

Programming Style

As always, all your work must follow these ten essential style items. See (snowmen.cxx for examples of this style. Also see www.cs.colorado.edu/~main/style.html.

The Assignment

Write a program that uses the four functions from the previous homework to draw a graphical simulation of a planet in orbit around a star. The program must:

  1. Start by asking the user to type four pieces of information about the simulation, like this (the boldface numbers are typed by the user):
    Please type the semi-major axis in A.U.: 3.2
    Please type the eccentricity in the range [0..1): 0.6
    Please type the period in days: 1000
    Please type the simulation rate in days/second: 180
    

  2. The program then opens a square graphics window of size S (a named constant), with double buffering turned on.

  3. The program then runs an animation loop. The loop is controlled by a time variable, t, that starts at zero days. Each iteration of the loop does these things:
    • Draw the next frame, consisting of the sun in the center of the screen and the planet which is at a location determined by the information a, ecc, period and t. The sun should be a filled in yellow ellipse with both radii equal to S/40. The planet is a blue filled ellipse with both radii equal to S/100.
    • Swap buffers and delay for 1/100 of a second.
    • Add days_per_second/100 to t.
The difficult step is drawing the planet at the right location. This must be done by a void function that you write:
draw_planet(a, ecc, period, t);
The function uses Kepler's method to compute the polar coordinates (r, theta) of the planet in astronomical units at time t. It then converts those values to Cartesian coordinates (x = r*cos(theta) and y = r*sin(theta)). Finally, it converts to pixel coordinates before drawing. For this last conversion, assume that the x and y coordinates can range from -2*a to +2*a.

The animation loop should be infinite (while (true)...), so that the only way to end the program is to click the close X or press ctrl-C.

Grading Criteria

  1. Your program must be called orbit.cxx. You must submit this file and no other.
  2. You must meet all the style requirements.
  3. Your code compiles correctly with no warnings.
  4. The behavior of your program must be correct.
  5. Additional requirement #1: You must use double buffering. Each iteration of the animation loop takes 1/100th of a second and simulates days_per_second/100 days of the actual orbit.
  6. You must have a function to draw the planet with the exact prototype show above. The coordinate conversions must be correct (which will make the planet travel counter-clockwise). You must also make use of the four functions from the previous assignment!