simulation.engine
Class Spring

java.lang.Object
  extended by simulation.engine.Spring

public final class Spring
extends java.lang.Object

A spring that connects to objects.

Author:
Jacob Taylor

Constructor Summary
Spring(double str, Body b1, Body b2, Vector connect1, Vector connect2)
          Create a spring with the given properties.
Spring(double len, double str, Body b1, Body b2, Vector connect1, Vector connect2)
          Create a spring with the given properties.
 
Method Summary
 Body connectedBody1()
          Get the first body the spring is connected to.
 Body connectedBody2()
          Get the second body the spring is connected to.
 void draw(java.awt.Graphics g)
          Draw the spring on a graphics object.
 double naturalLength()
          Get the natural length of the spring.
 void step(double amount)
          Have the spring apply force to its connections a certain amount.
 double strength()
          Get the spring's strength.
 Vector vertex1()
          Get the point where the spring is connected to the first body.
 Vector vertex2()
          Get the point where the spring is connected to the second body.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Spring

public Spring(double len,
              double str,
              Body b1,
              Body b2,
              Vector connect1,
              Vector connect2)
Create a spring with the given properties.

Parameters:
len - the natural length
str - the strength (k value)
b1 - the first body
b2 - the second body
connect1 - where it connects with the first body
connect2 - where it connects with the second body

Spring

public Spring(double str,
              Body b1,
              Body b2,
              Vector connect1,
              Vector connect2)
Create a spring with the given properties.

Parameters:
str - the strength (k value)
b1 - the first body
b2 - the second body
connect1 - where it connects with the first body
connect2 - where it connects with the second body
Method Detail

naturalLength

public double naturalLength()
Get the natural length of the spring.

Returns:
natural length

strength

public double strength()
Get the spring's strength.

Returns:
the strength

connectedBody1

public Body connectedBody1()
Get the first body the spring is connected to.

Returns:
the first body it is connected to

connectedBody2

public Body connectedBody2()
Get the second body the spring is connected to.

Returns:
the second body it is connected to

vertex1

public Vector vertex1()
Get the point where the spring is connected to the first body.

Returns:
the point where the spring is connected to the first body

vertex2

public Vector vertex2()
Get the point where the spring is connected to the second body.

Returns:
the point where the spring is connected to the second body

step

public void step(double amount)
Have the spring apply force to its connections a certain amount.

Parameters:
amount - the number of time units that have passed

draw

public void draw(java.awt.Graphics g)
Draw the spring on a graphics object.

Parameters:
g - graphics object