Due: Friday 3/5 10:00am

Submission name: w08_gravity

Calculate Gravity

Gravity is the attractive force exerted on an object by another object that has mass (something something curvature of spacetime something something). To find the force of gravity exerted on \(A\) by \(B\):

  • \[F = G \dfrac{mass_A mass_B}{r^2}\hat{AB}\]
  • Where \(r\) is the distance between \(A\) and \(B\). And \(\hat{AB}\) is the normalized vector from \(A\) to \(B\).
    • To calculate \({\overrightarrow AB}\), subtract \({\overrightarrow A}\) from \({\overrightarrow B}\) (in our code these are the center PVector fields).

Let’s get gravity right.

  • Start with the latest Orb code from thesource, which will include the mass stuff.
  • Add the method PVector getGravity(Orb o, float G)
    • This should calculate the force of gravity exerted on the calling object by o. This means that we should be seeing how o attracts the calling object.
    • This should return a PVector representing the force of gravity exerted on the calling object by o.
  • Create a driver file that makes 2 orbs that exert gravity on each other.
    • Play around with distances, masses and G values. You will probably get strange behavior.