1 package JSci.physics; 2 3 import JSci.maths.vectors.AbstractDoubleVector; 4 import JSci.maths.vectors.Double3Vector; 5 6 13 public class ClassicalParticle3D extends AbstractClassicalParticle { 14 17 protected double mass; 18 21 protected double x, y, z; 22 25 protected double vx, vy, vz; 26 29 public ClassicalParticle3D() {} 30 public void setMass(double m) { 31 mass=m; 32 } 33 public double getMass() { 34 return mass; 35 } 36 public void setPosition(double xPos, double yPos, double zPos) { 37 x=xPos; 38 y=yPos; 39 z=zPos; 40 } 41 public AbstractDoubleVector getPosition() { 42 return new Double3Vector(x, y, z); 43 } 44 public void setXPosition(double xPos) { 45 x=xPos; 46 } 47 public double getXPosition() { 48 return x; 49 } 50 public void setYPosition(double yPos) { 51 y=yPos; 52 } 53 public double getYPosition() { 54 return y; 55 } 56 public void setZPosition(double zPos) { 57 z=zPos; 58 } 59 public double getZPosition() { 60 return z; 61 } 62 public void setVelocity(double xVel,double yVel,double zVel) { 63 vx=xVel; 64 vy=yVel; 65 vz=zVel; 66 } 67 public AbstractDoubleVector getVelocity() { 68 return new Double3Vector(vx, vy, vz); 69 } 70 public double getXVelocity() { 71 return vx; 72 } 73 public double getYVelocity() { 74 return vy; 75 } 76 public double getZVelocity() { 77 return vz; 78 } 79 public double speed() { 80 return Math.sqrt(vx*vx+vy*vy+vz*vz); 81 } 82 public void setMomentum(double xMom,double yMom,double zMom) { 83 vx=xMom/mass; 84 vy=yMom/mass; 85 vz=zMom/mass; 86 } 87 public AbstractDoubleVector getMomentum() { 88 return new Double3Vector(mass*vx, mass*vy, mass*vz); 89 } 90 public double getXMomentum() { 91 return mass*vx; 92 } 93 public double getYMomentum() { 94 return mass*vy; 95 } 96 public double getZMomentum() { 97 return mass*vz; 98 } 99 102 public double energy() { 103 return mass*(vx*vx+vy*vy+vz*vz)/2.0; 104 } 105 110 public ClassicalParticle3D move(double dt) { 111 return translate(dt); 112 } 113 118 public ClassicalParticle3D translate(double dt) { 119 x+=vx*dt; 120 y+=vy*dt; 121 z+=vz*dt; 122 return this; 123 } 124 131 public ClassicalParticle3D accelerate(double ax,double ay,double az,double dt) { 132 vx+=ax*dt; 133 vy+=ay*dt; 134 vz+=az*dt; 135 return this; 136 } 137 144 public ClassicalParticle3D applyForce(double Fx,double Fy,double Fz,double dt) { 145 return accelerate(Fx/mass, Fy/mass, Fz/mass, dt); 146 } 147 152 public ClassicalParticle3D gravitate(ClassicalParticle3D p,double dt) { 153 final double dx=p.x-x; 154 final double dy=p.y-y; 155 final double dz=p.z-z; 156 final double rr=dx*dx+dy*dy+dz*dz; 157 final double r=Math.sqrt(rr); 158 final double g=p.mass/rr; 159 final double pg=mass/rr; 160 vx-=g*dx*dt/r; 161 vy-=g*dy*dt/r; 162 vz-=g*dz*dt/r; 163 p.vx+=pg*dx*dt/r; 164 p.vy+=pg*dy*dt/r; 165 p.vz+=pg*dz*dt/r; 166 return this; 167 } 168 } 169 170 | Popular Tags |