This is the web version of EJS interface
EJS version 4.2.7
  1. CaptureTools=true
  2. DataTools=true
  3. LanguageTools=true
  4. EmersionSupport=true
  5. UseInterpreter=true
  6. AuxiliaryFiles=_data/_data1/Freeze.gif;_data/_data1/Pause.gif;_data/_data1/play.gif;_data/_data1/Reset.gif;_data/_data1/Step.gif;_data/_data1/rect wall.gif;_data/_data1/circle wall.gif;_data/_data1/No Parts.gif;_data/_data1/No Walls.gif;_data/_data1/Save.gif;_data/_data1/Read.gif;_data/_data1/Collapse.gif;
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension
    numParticles = 2; resistance = 0.01; for (int i=0; i<maxParticles; i++) { if (i%2==0) { type[i] = 1; size[i] = (maximum-minimum)/40.0; charge[i] = 1.0; color[i] = java.awt.Color.blue; } else { type[i] = 10; size[i] = (maximum-minimum)/50.0; charge[i] = -1.0; color[i] = java.awt.Color.red; } visible[i] = i<numParticles; x[i] = minimum/2. + i*maximum;//(maximum-minimum)*Math.random(); y[i] = 0;//minimum + (maximum-minimum)*Math.random(); double angle = 2.0*Math.PI*Math.random(); vx[i] =0.;// speed*(Math.random ()-0.5); vy[i] =0.;// speed*(Math.random ()-0.5); particleFixed[i]=fixed; }
    double step = (maximum - minimum)/(resolution-1); for (int i=0; i<resolution; i++) { for (int j=0; j<resolution; j++) { field[i][j][0] = minimum + step*i; field[i][j][1] = minimum + step*j; potential[i][j][0] = minimum + step*i; potential[i][j][1] = minimum + step*j; } }
    Indep. Var. Increment
    d x[i] /dtime=vx[i]
    d y[i] /dtime=vy[i]
    d vx[i] /dtime=force(i,x,y,true)/mass[i]
    d vy[i] /dtime=force(i,x,y,false)/mass[i]
    SolverRungeKutta

    Compute derived variables

    // Store previous positions in case of collision with walls for (int i=0; i<numParticles; i++) { xPrev[i] = x[i]; yPrev[i] = y[i]; } // compute the field computeVectorField (); computePotential (); computeField(newX,newY); // This needs to be the last one
    private double force(int particle, double a[], double b[], boolean xAxis) { double force = 0.0, r2,efield; if(particleFixed[particle])return 0.0; if (particle>=numParticles) return 0.0; for (int i=0; i<numParticles; i++) { if (i==particle) continue; r2 = (a[i]-a[particle])*(a[i]-a[particle]) + (b[i]-b[particle])*(b[i]-b[particle]); if (r2<threshold) continue; if (xAxis) force += K*charge[i]*charge[particle]*(a[particle]-a[i])/r2; else force += K*charge[i]*charge[particle]*(b[particle]-b[i])/r2; } if(xAxis)efield=Efieldx; else efield=Efieldy; return force+charge[particle]*efield; } private void computeField (double a, double b) { double force = 0.0, r2; Ex=0.0; Ey=0.0; for (int i=0; i<numParticles; i++) { r2 = (x[i]-a)*(x[i]-a) + (y[i]-b)*(y[i]-b); if (r2<threshold) continue; Ex += K*charge[i]*(a-x[i])/r2; Ey += K*charge[i]*(b-y[i])/r2; } Ex+=Efieldx; Ey+=Efieldy; } public void computeVectorField () { if (showVectorField) for (int i=0; i<resolution; i++) { for (int j=0; j<resolution; j++) { computeField(field[i][j][0],field[i][j][1]); double r=Math.sqrt(Ex*Ex+Ey*Ey); field[i][j][2] = Ex/r; field[i][j][3] = Ey/r; field[i][j][4] = r; } } } private double computePotential (double a, double b) { double pot = 0.0, r2; for (int i=0; i<numParticles; i++) { r2 = (x[i]-a)*(x[i]-a) + (y[i]-b)*(y[i]-b); if (r2<threshold) continue; pot -= K*charge[i]*Math.log(r2)*0.5; } return pot; } public void computePotential () { if (showPotential || showCheckerPotential || showPotential3D) for (int i=0; i<resolution; i++) { for (int j=0; j<resolution; j++) { potential[i][j][2] = computePotential(potential[i][j][0],potential[i][j][1]); } } } public void computePotentialExtrema () { if (!(showPotential || showCheckerPotential || showPotential3D)) { potentialMinimum = 0.0; potentialMaximum = 1.0; return; } computePotential(); double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (int i=0; i<resolution; i++) { for (int j=0; j<resolution; j++) { min = Math.min (min,potential[i][j][2]); max = Math.max (max,potential[i][j][2]); } } potentialMinimum = min; potentialMaximum = max; }
    Array