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)
toOrb
- 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 pastspringLength
and should push the calling object away fromo
if the spring is compressed to be less thanspringLength
.
- This should calculate the force felt on the calling object of a spring between the calling object and
- Create a driver file that tests the spring force. This should not have extra pieces. A single
FixedOrb
and regularOrb
will suffice. Adding gravity (either as a constant downward force or usingFixedOrb
as discussed in class), can provided a constant “pulling” on the spring to help test.