/**
   * force calculation on input masses
   *
   * @param masses - input masses to apply force to
   */
  @Override
  protected void envoke(List<Mass> masses) {
    for (Mass mass : masses) {
      double distance = getDistance(mass);
      Vector force = calculateWallRepulsionForce(distance);

      mass.applyAccelerationVector(force);
    }
  }
 /**
  * gets the distance between this repulsion force's wall and the input mass
  *
  * @param mass - mass to find the distance to
  * @return dist - distance to mass
  */
 public double getDistance(Mass mass) {
   double dist = 0;
   if (mySide == TOP_WALL) {
     dist = mass.getY();
   } else if (mySide == RIGHT_WALL) {
     dist = mass.getX();
   } else if (mySide == BOTTOM_WALL) {
     dist = mass.getY() - myHeight;
   } else if (mySide == LEFT_WALL) {
     dist = mass.getX() - myWidth;
   }
   return dist;
 }
Esempio n. 3
0
 @Override
 public Vector getForceOnMass(Mass m) {
   if (!getToggle()) return new Vector();
   Vector result = new Vector(m.getVelocity());
   double viscosityScale = getProperty(Keywords.SCALE);
   result.setMagnitude(result.getMagnitude() * viscosityScale);
   result.turn(Keywords.DEGREES_TURN_AROUND);
   return result;
 }
 /** Convenience method. */
 public double distance(Mass other) {
   // this is a little awkward, so hide it
   return new Location(getX(), getY()).distance(new Location(other.getX(), other.getY()));
 }
 public void applyVescosity(Mass m) {
   Vector vescoForce = new Vector(m.getVelocity());
   vescoForce.scale(myViscosity);
   vescoForce.negate();
   m.applyForce(vescoForce);
 }
 public void applyGravity(Mass m) {
   Vector g = new Vector(getMyGravity());
   g.scale(m.getMyMass());
   m.applyForce(g);
 }
 public void applyRepulsionForce(Mass m, Dimension bounds) {
   for (WallRepulsion wr : myWalls) {
     Vector repForce = wr.getForce(m, bounds);
     m.applyForce(repForce);
   }
 }
 public void applyCenterAttraction(Mass m) {
   Vector attForce = myCenter.getForce(m);
   m.applyForce(attForce);
 }