public class Spring extends TwoBodyForce
TwoBodyForce to calculate
the force with a spring constant (ks), damping factor (d), and an
ideal length (l). Thus, the positions of the Particles on either end
obey the equation:ddot(r) = -k/m * (r-l) - d/m * dot(r)TwoBodyForce.ForcePair| Constructor and Description |
|---|
Spring(Particle oneEnd,
Particle theOtherEnd,
float ks,
float d,
float l)
Creates a spring with the given properties between the given particles.
|
| Modifier and Type | Method and Description |
|---|---|
float |
currentLength()
Gets the current Spring length; uses the end particle positions to do so.
|
float |
damping()
Reports the damping constant of the spring
d; Will always be greater than 0. |
TwoBodyForce.ForcePair |
forcePair()
Calculates the spring forces on each of the particles at either end of the spring.
|
float |
restLength()
Reports the ideal length,
l; always more than 0. |
Spring |
setDamping(float d)
Sets the damping constant of the spring
d. |
Spring |
setRestLength(float l)
Sets the ideal length of the spring.
|
Spring |
setStrength(float ks)
Sets the strength of the spring
ks; must be greater than 0. |
float |
strength()
Reports the strength of the spring
ks; always more than 0. |
apply, equalAndOpposite, getOneEnd, getTheOtherEnd, setOneEnd, setTheOtherEnd, specifyBoth, turnOff, turnOn, turnOnapplyisOff, isOnpublic Spring(Particle oneEnd, Particle theOtherEnd, float ks, float d, float l) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
oneEnd - the one end Particle; cannot be nulltheOtherEnd - the other end Particle; cannot be nullks - the spring constant.d - the damping constant.l - the ideal length of the spring.java.lang.NullPointerException - if either Particle is null, via TwoBodyForce.TwoBodyForce(Particle, Particle)java.lang.IllegalArgumentException - if l is not positive, via setRestLength(float).java.lang.IllegalArgumentException - if ks not positive, via setStrength(float).java.lang.IllegalArgumentException - if d less than 0, via setDamping(float).public final float currentLength()
public final float restLength()
l; always more than 0.public final Spring setRestLength(float l) throws java.lang.IllegalArgumentException
l - the new rest length; must be positive.java.lang.IllegalArgumentException - if rest length is negativepublic final float strength()
ks; always more than 0.ks, the spring constantpublic final Spring setStrength(float ks) throws java.lang.IllegalArgumentException
ks; must be greater than 0.ks - the new spring constant; must be greater than 0.java.lang.IllegalArgumentException - if ks is not positive.public final float damping()
d; Will always be greater than 0.d, the damping constant.public final Spring setDamping(float d) throws java.lang.IllegalArgumentException
d.d - the new damping constant. Must not be negative but can be 0 for no damping.java.lang.IllegalArgumentException - if d is negative.public TwoBodyForce.ForcePair forcePair()
forcePair in class TwoBodyForce