SOLAR.SYSTEM.SIM

GOAL: Model the solar system by simulating gravity & calculating each planet's changing position/velocity
SYNPOSIS: Individual project | Winter 2018 | Python
KEY SKILLS: Animation | Objects | Physics kinematic equations
VIDEO OF SIMULATOR

Yellow=Sun | Orange=Mercury | Green=Venus | Blue=Earth | Red=Mars

Key Process:

  1. Created a planet object with mass, radius, color, velocity in the x/y direction, and x/y position as instance variables
  2. Created a system object with list of planet objects as the instance variable
  3. Wrote a 'compute acceleration' method that computes the total gravitational force on a single planet by summing up the gravitational attraction from each planet in the system using: \(F_g = {G(m_1)(m_2) \over r^2}\)
  4. Wrote a 'update' method that takes 'time elapsed' as a parameter. The method first computes the total acceleration on each planet based on the current location of the planets around it. Then, it updates the x/y position & x/y velocity instance variables of each planet in the system using \(x_f = x_i + v_x * t\) and \(v_f=v_i + a_x*t\)
  5. Set a meters to pixel conversion and used it to draw the scaled position of each planet
  6. Set a timescale conversion representing real seconds per simulation second. Used it to update the positions of each planet with respect to time, creating an animation.