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).
- To calculate \({\overrightarrow AB}\), subtract \({\overrightarrow A}\) from \({\overrightarrow B}\) (in our code these are the
Let’s get gravity right.
- Start with the latest
Orb
code from thesource, which will include themass
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 howo
attracts the calling object. - This should return a
PVector
representing the force of gravity exerted on the calling object byo
.
- This should calculate the force of gravity exerted on the calling object by
- 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.
- Play around with distances, masses and