private void applyForces(final double dt) {
   for (final Object object : this.particles.keySet()) {
     final Particle particle = this.particles.get(object);
     final Vector oldSpeed = particle.getSpeed();
     final Vector newSpeed = oldSpeed.add(this.forces.get(object).scale(dt / particle.getMass()));
     particle.setSpeed(newSpeed);
   }
 }
 void dyn(Particle p) {
   if (bounds != null && !bounds.contains(p.getRx(), p.getRy())) return;
   double temp = Math.abs(b) * p.charge * MDModel.GF_CONVERSION_CONSTANT / p.getMass();
   if (o == OUTWARD) temp = -temp;
   p.fx += temp * p.vy;
   p.fy -= temp * p.vx;
   if (p instanceof GayBerneParticle) {
     GayBerneParticle gb = (GayBerneParticle) p;
     if (Math.abs(gb.dipoleMoment) > 0) {
       temp = Math.cos(gb.theta) * gb.vx + Math.sin(gb.theta) * gb.vy;
       if (o == OUTWARD) temp = -temp;
       gb.tau -= gb.dipoleMoment * temp * b / gb.inertia * MDModel.GF_CONVERSION_CONSTANT;
     }
   }
 }
Beispiel #3
0
  private void update(Particle particle) {

    float intervalInSecs = (float) intervalInMillis / 1000f; // e.g. 0.033

    // position
    Vector velocity = particle.getVelocity().clone();
    velocity.multiply(intervalInSecs);
    Vector newPosition = particle.getPosition();
    newPosition.add(velocity);
    particle.setPosition(newPosition);

    // velocity
    float dampPowTime = (float) Math.pow(particle.getMass(), intervalInSecs);
    Vector velocityMult = particle.getVelocity().clone();
    velocityMult.multiply(dampPowTime);

    Vector acceleration = particle.getAcceleration().clone();
    acceleration.multiply(intervalInSecs);

    velocityMult.add(acceleration);
    particle.setVelocity(velocityMult);
  }