Esempio n. 1
0
 public boolean isValidList2Position(Vector3d position) {
   for (int i = 0; i < pcList2.size(); i++) {
     PointCharge pc = (PointCharge) pcList2.get(i);
     Point3d pcPosition = new Point3d(pc.getPosition());
     if (pcPosition.distance(new Point3d(position)) < pc_radius * 1.5) {
       return false;
     }
   }
   if (Math.abs(position.x - plate2_position.x) > plate_length / 2. - pc_radius) return false;
   if (Math.abs(position.y - plate2_position.y) > plate_height / 2. - pc_radius) return false;
   if (Math.abs(position.z - plate2_position.z) > plate_width / 2. - pc_radius) return false;
   return true;
 }
Esempio n. 2
0
  private void resetPointCharges() {
    removeChargesFromList1(pcList1.size());
    removeChargesFromList2(pcList2.size());
    int N1 = 0;
    try {
      N1 = Integer.parseInt(plate1Number.getText());
    } catch (NumberFormatException e) {
      N1 = N;
      plate1Number.setText(String.valueOf(N));
    }
    if (N1 < 0) {
      N1 = 0;
      plate1Number.setText("0");
    }
    int N2 = 0;
    try {
      N2 = Integer.parseInt(plate2Number.getText());
    } catch (NumberFormatException e) {
      N2 = N;
      plate2Number.setText(String.valueOf(N));
    }
    if (N2 < 0) {
      N2 = 0;
      plate2Number.setText("0");
    }
    addChargesToList1(N1);
    addChargesToList2(N2);

    double charge1 = 0;
    try {
      charge1 = Double.parseDouble(plate1Charge.getText());
    } catch (NumberFormatException e) {
      charge1 = pc_charge;
      plate1Charge.setText(String.valueOf(charge1));
    }
    double charge2 = 0;
    try {
      charge2 = Double.parseDouble(plate2Charge.getText());
    } catch (NumberFormatException e) {
      charge2 = -pc_charge;
      plate2Charge.setText(String.valueOf(charge2));
    }
    for (int i = 0; i < pcList1.size(); i++) {
      PointCharge pc = (PointCharge) pcList1.get(i);
      pc.setCharge(charge1);
    }
    for (int i = 0; i < pcList2.size(); i++) {
      PointCharge pc = (PointCharge) pcList2.get(i);
      pc.setCharge(charge2);
    }
  }
Esempio n. 3
0
  public void addChargesToList2(int number) {
    for (int k = 0; k < number; k++) {
      Vector3d position = new Vector3d();
      int count = 0;
      do {
        count++;
        double x = (2. * Math.random() - 1.) * (plate_length / 2. - pc_radius);
        double y = (2. * Math.random() - 1.) * (plate_height / 2. - pc_radius);
        double z = (2. * Math.random() - 1.) * (plate_width / 2. - pc_radius);
        position.set(x, y, z);
        position.add(plate2_position);
      } while (!isValidList2Position(position));

      double charge = 0.;
      if (!pcList2.isEmpty()) charge = ((PointCharge) pcList2.get(0)).getCharge();
      else charge = -pc_charge;

      PointCharge pc = new PointCharge();
      pc.setPosition(position);
      pc.setCharge(charge);
      pc.setRadius(pc_radius);

      pc.setMass(1.0);
      pc.setID("pcList2_charge" + pcList2.size());
      pc.setPickable(false);
      pc.setColliding(true);
      pc.setGeneratingP(false);

      SphereCollisionController scc = new SphereCollisionController(pc);
      scc.setRadius(pc_radius);
      scc.setTolerance(0.5);
      scc.setMode(SphereCollisionController.WALL_SPHERE);
      pc.setCollisionController(scc);
      addElement(pc);
      pcList2.add(pc);
    }
  }
Esempio n. 4
0
 public void actionPerformed(ActionEvent e) {
   String command = e.getActionCommand();
   System.out.println("Action: " + command);
   if (e.getActionCommand().compareToIgnoreCase("Capacitor2") == 0) {
     if ((mFramework != null) && (mFramework instanceof TFramework)) {
       ((TFramework) mFramework).openBrowser("help/capacitor.html");
     } else {
       TDebug.println("mFramework is null!");
     }
   } else if (e.getSource() == plate1Number) {
     int value = 0;
     try {
       value = Integer.parseInt(plate1Number.getText());
     } catch (NumberFormatException exception) {
       return;
     }
     if (value < 0) {
       value = 0;
       plate1Number.setText("0");
     }
     int change = value - pcList1.size();
     if (change > 0) {
       addChargesToList1(change);
     } else {
       removeChargesFromList1(-change);
     }
   } else if (e.getSource() == plate2Number) {
     int value = 0;
     try {
       value = Integer.parseInt(plate2Number.getText());
     } catch (NumberFormatException exception) {
       return;
     }
     if (value < 0) {
       value = 0;
       plate2Number.setText("0");
     }
     int change = value - pcList2.size();
     if (change > 0) {
       addChargesToList2(change);
     } else {
       removeChargesFromList2(-change);
     }
   } else if (e.getSource() == plate1Charge) {
     double value = 0.;
     try {
       value = Double.parseDouble(plate1Charge.getText());
     } catch (NumberFormatException exception) {
       return;
     }
     for (int i = 0; i < pcList1.size(); i++) {
       PointCharge pc = (PointCharge) pcList1.get(i);
       pc.setCharge(value);
     }
   } else if (e.getSource() == plate2Charge) {
     double value = 0.;
     try {
       value = Double.parseDouble(plate2Charge.getText());
     } catch (NumberFormatException exception) {
       return;
     }
     for (int i = 0; i < pcList2.size(); i++) {
       PointCharge pc = (PointCharge) pcList2.get(i);
       pc.setCharge(value);
     }
   } else {
     super.actionPerformed(e);
   }
 }