1 package JSci.physics; 2 3 import JSci.maths.vectors.AbstractDoubleVector; 4 import JSci.maths.vectors.DoubleVector; 5 6 12 public class ClassicalParticle extends AbstractClassicalParticle { 13 protected double mass; 14 protected AbstractDoubleVector x; 15 protected AbstractDoubleVector v; 16 20 public ClassicalParticle(int n) { 21 x = new DoubleVector(n); 22 v = new DoubleVector(n); 23 } 24 27 public void setMass(double m) { 28 mass = m; 29 } 30 33 public double getMass() { 34 return mass; 35 } 36 public void setPosition(AbstractDoubleVector pos) { 37 x = pos; 38 } 39 public AbstractDoubleVector getPosition() { 40 return x; 41 } 42 public void setVelocity(AbstractDoubleVector vel) { 43 v = vel; 44 } 45 public AbstractDoubleVector getVelocity() { 46 return v; 47 } 48 private double speedSqr() { 49 return v.scalarProduct(v); 50 } 51 public double speed() { 52 return v.norm(); 53 } 54 public void setMomentum(AbstractDoubleVector momentum) { 55 v = momentum.scalarDivide(mass); 56 } 57 public AbstractDoubleVector getMomentum() { 58 return v.scalarMultiply(mass); 59 } 60 63 public double energy() { 64 return mass*speedSqr()/2.0; 65 } 66 71 public ClassicalParticle move(double dt) { 72 x = x.add(v.scalarMultiply(dt)); 73 return this; 74 } 75 82 public ClassicalParticle accelerate(AbstractDoubleVector a, double dt) { 83 v = v.add(a.scalarMultiply(dt)); 84 return this; 85 } 86 93 public ClassicalParticle applyForce(AbstractDoubleVector F,double dt) { 94 return accelerate(F.scalarDivide(mass), dt); 95 } 96 } 97 98 | Popular Tags |