Due: Wednesday 3/12 10:00am

Submission name: w10_spring

Spring Physics

Relevant Physics to find the force a spring connecting \(A\) to \(B\), where \(B\) is a fixed point:

  • \[F = kx\hat{AB}\]
  • Where \(k\) is the spring constant,
  • \(x\) is the displacement, or difference of the distance between \(A\) and \(B\) and the length of the spring.
  • \(\hat{AB}\) is the normalized vector from \(A\) to \(B\).

Spring Code

  • Start with the code for FixedOrbRunner in thesource
  • Add the method PVector getSpring(Orb o, int springLength, float springConstnat) to Orb
    • This should calculate the force felt on the calling object of a spring between the calling object and o.
    • The resulting force should pull the calling object towards o if the spring is extended past springLength and should push the calling object away from o if the spring is compressed to be less than springLength.
  • Create a driver file that tests the spring force. This should not have extra pieces. A single FixedOrb and regular Orb will suffice. Adding gravity (either as a constant downward force or using FixedOrb as discussed in class), can provided a constant “pulling” on the spring to help test.

Reference Image:

a10-spring