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); } }