Vector qPos(double timeT) { if(timeT < 1) { return new Vector(timeT*200,180,0); } if(timeT < 3) { return new Vector(200*timeT - 50*(timeT-1)*(timeT-1),180,0); } else { return new Vector(400,180,0); } } Vector qVel(double timeT) { if(timeT < 1) { return new Vector(200,0,0); } if(timeT < 3) { return new Vector(300-100*timeT,0,0); } else { return new Vector(0,0,0); } } Vector qAcc(double timeT) { if(timeT < 1) { return new Vector(0,0,0); } if(timeT < 3) { return new Vector(-100,0,0); } else { return new Vector(0,0,0); } } // critical method: will return the time that the particle contributes, // so you can plug it into other things double c = 250; // speed of light = 150 pix/second double retardedTime(Vector fieldPoint,double fieldTime) { double tr = fieldTime; Vector displacementVector = qPos(tr); displacementVector.sub(fieldPoint); int i = 0; while( abs((float)(tr+displacementVector.length()/(c) - fieldTime)) > 0.02 ) { tr -= (tr+displacementVector.length()/(c) - fieldTime); displacementVector.set(qPos(tr)); displacementVector.sub(fieldPoint); if(i++>10) { break; } } return tr; } void setup() { size(600,400); frameRate(30); } Vector E(Vector fieldPoint,double fieldTime) { double tr = retardedTime(fieldPoint,fieldTime); Vector r = fieldPoint; r.sub(qPos(tr)); Vector v = qVel(tr); Vector a = qAcc(tr); a.mul(10); Vector u = new Vector(r); u.normalize(); u.mul(c); u.sub(v); double rdu = Vector.dot(r,u); double scaleFactor = r.length() / (rdu*rdu*rdu); Vector t1 = Vector.mul(u,(c*c-v.lengthSquared())); //t1.mul(10); Vector t2 = Vector.cross(r,Vector.cross(u,a)); //t2.mul(r.length()); //t2.mul(10); t1.add(t2); t1.mul(scaleFactor); //t1.mul(r.length()); return t1; } double time = 0; void mousePressed() { time = 0; } void draw() { background(0,0,0); stroke(255,255,255); noStroke(); fill(0,0,30); rect(200,-10,800,500); time = ((double)mouseX / (double)width) * 5.0; for(float x = 0 ; x <= width ; x+=10) { for(float y = 0 ; y <= height ; y+=10) { Vector e = E(new Vector(x,y,0),time); e.mul(10000); if(e.lengthSquared() >= 100) { e.normalize(); e.mul(10); } if(e.lengthSquared() <= 200) { float l = (float)(e.length()/10 * 255); stroke(l,l,l); line(x,y,x+(float)e.x,y+(float)e.y); } } } fill(200,200,200); ellipseMode(CENTER); ellipse((float)(qPos(time).x),(float)(qPos(time).y),10,10); // time += 0.05; }