package jsci.physics;
import jsci.maths.vectors.AbstractDoubleVector;
import jsci.maths.vectors.DoubleVector;
public class Spring {
private final double coefficient;
private AbstractDoubleVector x;
/**
* Constructs a mechanical spring.
* @param coeff the spring constant.
*/
public Spring(double coeff) {
coefficient = coeff;
}
public void setPosition(AbstractDoubleVector pos) {
x = pos;
}
public AbstractDoubleVector getPosition() {
return x;
}
/**
* Returns the potential energy of a particle attached to this spring.
*/
public double energy(AbstractClassicalParticle p) {
double rr = 0.0;
AbstractDoubleVector ppos = p.getPosition();
for(int i=0; i
Ads help maintain this website.