Example #1
0
  public static Simulation initSpring(int count, double radius) {
    Settings stt = new Settings();

    stt.setTimeStep(1);
    stt.setSpeedOfLight(3);
    stt.setSimulationWidth(100);
    stt.setSimulationHeight(100);

    stt.addForce(new ConstantForce());
    stt.addForce(new SpringForce());

    stt.setNumOfParticles(count);
    stt.setParticleRadius(radius);
    stt.setParticleMaxSpeed(stt.getSpeedOfLight());

    stt.setBoundary(GeneralBoundaryType.Periodic);
    stt.setParticleSolver(new EulerRichardson());

    for (int k = 0; k < count; k++) {
      Particle par = new Particle();
      par.setX(stt.getSimulationWidth() * Math.random());
      par.setY(stt.getSimulationHeight() * Math.random());
      par.setRadius(15);
      par.setVx(10 * Math.random());
      par.setVy(0);
      par.setMass(1);
      par.setCharge(.001);
      stt.addParticle(par);
    }

    Simulation simulation = new Simulation(stt);
    return simulation;
  }
Example #2
0
  /**
   * Creates particles on random positions with random speeds
   *
   * @param width maximal x-coodrinate
   * @param height maximal y-coordinate
   * @param maxspeed maximal particle speed
   * @param count number of particles to be created
   * @param radius particle radius
   * @return ArrayList of Particle2D
   */
  public static ArrayList<Particle> createRandomParticles(
      double width, double height, double maxspeed, int count, double radius) {

    ArrayList<Particle> particlelist = new ArrayList<Particle>(count);

    for (int k = 0; k < count; k++) {
      Particle p = new Particle();
      p.setX(width * Math.random());
      p.setY(height * Math.random());
      p.setRadius(radius);
      phi = 2 * Math.PI * Math.random();
      p.setVx(maxspeed * Math.cos(phi));
      p.setVy(maxspeed * Math.sin(phi));
      p.setMass(1);
      if (Math.random() > 0.5) {
        p.setCharge(.1);
      } else {
        p.setCharge(-.1);
      }
      particlelist.add(p);
    }

    return particlelist;
  }