We are about to switch to a new forum software. Until then we have removed the registration on this forum.
/* Electric field pattern generated by two charges, simulation of the classical experiment
with semolina seed in castor oil (see: www.youtube.com/watch?v=7vnmL853784)
(my first Sketch) */
size(1000,700); background(255);
int cpx=200, cpy=350; // position of the first charge (the one on the left)
int cnx=800, cny=350; // position of the second charge (the one on the right)
int qp=1000, qn=-1000;// values of the charges; try qn=1000 and different combinations (e.g. qp=10, qn=1000)
int x,y,dx,dy,dxn,dyn;
float d1,E1,E1x,E1y,d2,E2,E2x,E2y;
float EEx,EEy,EE,ll,deltax,deltay;
fill(0); ellipse(cpx,cpy,8,8);
fill(120); ellipse(cnx,cny,8,8);
fill(0);
ll=15; // grains of semolina dimension (try ll=10, ll=20)
int ns=20000; // number of grains (try ns=10000, ns=30000)
for(int i=0; i<ns; i++)
{
x=int(random(1000));
y=int(random(700));
dx=x-cpx; dy=y-cpy;
d1=sqrt(dx*dx+dy*dy);
E1=qp/(d1*d1);
E1x=dx*E1/d1;
E1y=dy*E1/d1;
dxn=x-cnx; dyn=y-cny;
d2=sqrt(dxn*dxn+dyn*dyn);
E2=qn/(d2*d2);
E2x=dxn*E2/d2;
E2y=dyn*E2/d2;
EEx=E1x+E2x;
EEy=E1y+E2y;
EE=sqrt(EEx*EEx+EEy*EEy);
deltax=ll*EEx/EE;
deltay=ll*EEy/EE;
line(x,y,x+deltax,y+deltay);
}
Comments
My first Sketch. Be patient and excuse my English
very nice!
Thank you Chrisir, very good improvement, I'll study it and I'm sure your sketch will be useful to improve my knowledge of Processing. I teach Maths and Physics in an Italian high school and I wondered about the pattern field of the interaction of a uniform electric field with the one generated by a single charge. Of course, you can imagine it, but, what about a simulation program? First I tried a situation I already knew (Electric field pattern generated by two charges), then I wrote the following sketch:
It looks very nice, it is a piece of art.
It's always great to see science visualized with a bit of code! *-:)
Next up, making it 3D?
I wonder how make complete uniterruoted lines ?
and what if one pole ist stronger ?
long and mesy version for Field and equipotential line (not so efficient for the equi)
When you use a Particle system you can visualize the flow of the electric field.
Adapted Code Example
Look like the magnetic field of the earth :p
Thanks for your contributions. As a matter of fact, these are my first attempts with Processing (and with Java as well) and I have a lot to learn. If I try to run "amnon code", I get "Processing cannot run because GLSL shaders are not available"; if I try to run "sus code" I get "the method append(int) in the type FloatList is not applicable for the arguments (float). I don't know if submitting my naive experiments in the "Share your work" section is a good idea; I'm a beginner and the section is probably designed for more skilled people. Thanks a lot anyway ... I'll learn
Which Processing version are you using? In @amnon's code, replace P2D by JAVA2D @ line #10.
P.S.: Mine's v2.0.2. It's far from the latest version, but it's enough to run both codes!
My version is 2.0b8 (time to get a more recent one?). I replaced P2D with JAVA2D and ... it worked fine. Thank you GoToLoop !
Then you are using a really old beta version.
I would strongly advise you to download the latest version: 2.2.1 (19 May 2014)
Amazing! :)
Article deserves pictures. I modified "Adapted Code Example" to assign random color for each particle via:
and
and changed
Another image with
matured
Really nice work. You should check if you can pen plot it somewhere.
Really beautiful! Thanks jas0501.