Physics, Art, and Programming Ben Hoffman

 

There are many times that computers can help humans do things that could not be done by hand. Many of these things can be expressed mathematically as a sum but can not be calculated on paper because of the extremely large number of simple calculations. The example that I've been working with is the sum of electric fields and the field lines they can produce. It is easy to acquire the electric field vector due to a set of charged particles at a given point, but to create a smooth line that follows those vectors requires more computing power than just a paper and pencil. While there are specific rules for drawing field lines, they don't draw the pictures for you. It may be easy to follow these rules and in a simple system (only two or three charges), but a computer is needed to keep the rules in check for more complicated systems.

Some of the rules that we know are:

A) Field lines add up vectorially and can be split into components that act separately.

B) Field lines, if drawn correctly, do not cross.

C) The component of the electric field from one charged particle has no effect on the components of the other charged particles' electric field.

D) The electric field is proportional to 1/r^2 where r is the distance between the charge and the test point.

These rules allow us to imagine what a set of field lines might look like but more importantly they allow us to set up a system for drawing them as close to what they would actually look like as the human eye can tell. So, I wrote a program to do just that.

 

An explanation of HOW IT WORKS:

At root, the program is really pretty simple, it was only a few things that take to work and creativity to get around. The idea is to draw a series of vector sums of the summed electric fields end to end. If each of these vectors is close to being a unit vector (one pixel in length) then the drawing will turn out just as if the vectors were drawn infinitesimally small. Basically all of the locations of the charges and their values are given to the computer in a Cartesian format. Then a test point is assigned near a positive charge. A unit vector is then determined from the sum of the X and Y components of all of the electric fields. The a temporary test point is assigned to the location of the old test point and the old test point is moved to the end of the vector. A line is drawn from one point to the other and the process is repeated starting at the new point.

This is the part of the process that presents all of the problems. Because the vectors' sizes drop off according to 1/r^2, the test point starts move slower exponentially. Before long the test point isn't moving at all (if its traveling away from charges). At these rates it would take an extremely long time to draw just one field line.

Another problem arises from the same 1/r^2 falloff. When the test point gets near a negative charge it starts to accelerate; Inotherwords, the vectors are very large when we are talking about areas that are very near to the negative charges. Sometimes the test points will go right past the charges and go into a wild orbit around them.

A third problem that I encountered was from the field lines that were entirely in a direction that was parallel to the electric field sum. This made it so that they didn't divert any from their path and would continue on indefinitely.

SOME SOLUTIONS to these problems may seem fairly apparent after the fact but hung me up for a great deal of time. The key to solving most of my problems had to do with making each of the field lines relatively finite. This means that

a) The field lines had to come to an end when they came within a certain distance of the negative charges

b) The field lines had to come to an end when they attained a certain large radius from the system

Part b of the solution violates some of the rules of electric field lines. Richard P. Feynman, a notable physicist, wrote down several rules (many more than I have here) for drawing field lines and equipotential surfaces. One of the rules near the top of the list was that the number of field lines that start in a closed system end on the negatively charged particles. Part be will violate this rule but is necessary in order to make the rendering of these images possible in a feasible amount of time. For example, the line that would start just above the line in the picture above has to travel a ridiculous distance before getting to the negative charge.

Another way to bring this infinitesimal process down to a reasonable finite level is to convert each vector drawn into the unit vectors discussed above:

c) Multiply each vector by a multiple of the square of the radius to the nearest electric field generating particle

This allows all of the vectors to be the same length so that the test point does not stop or fly into a frenzy orbit around a negative charge.

 

THE CODE:


put 640 into px
put 600 into py
put 1 into q

put 400 into qx
put 400 into qy
put 14 into q2

put 300 into rx
put 300 into ry
put -30 into q3

put 1000 into ox
put 600 into oy
put -10 into q4

put 100 into wx
put 620 into wy
put 10 into q5

put 400 into ex
put 400 into ey
put -10 into q6

put px into sx
put py into sy
put px into sxx
put py into syy
put 0 into r
put 0 into r2
put 0 into r3
put 0 into r4
put 0 into r5
put 0 into r6
put 0 into a
put 0 into a2
put 0 into a3
put 0 into a4
put 0 into a5
put 0 into a6

put 0 into m
put 0 into course
put 0 into inf
put 0 into rot
put 0 into rotx
put 0 into roty
choose the line tool


repeat until rot = 7
add 1 to rot

if rot = 1 then
put px into rotx
put py into roty
end if


if rot = 2 then
put qx into rotx
put qy into roty
end if

if rot = 3 then
put rx into rotx
put ry into roty
end if


if rot = 4 then
put ox into rotx
put oy into roty
end if

if rot = 5 then
put wx into rotx
put wy into roty
end if

if rot = 6 then
put ex into rotx
put ey into roty
end if


put 0 into m
repeat until m > pi*2

add (2*pi)/20 to m
put -15*sin(m) + roty into sy
put 15*cos(m) + rotx into sx
put 0 into course

repeat until course = 1198
add one to course
put ((sx-px)^2+(sy-py)^2)^.5 into r
put ((sx-qx)^2+(sy-qy)^2)^.5 into r2
put ((sx-rx)^2+(sy-ry)^2)^.5 into r3
put ((sx-ox)^2+(sy-oy)^2)^.5 into r4
put ((sx-wx)^2+(sy-wy)^2)^.5 into r5
put ((sx-ex)^2+(sy-ey)^2)^.5 into r6
put atan((sy-py)/(sx-px)) into a
put atan((sy-qy)/(sx-qx)) into a2
put atan((sy-ry)/(sx-rx)) into a3
put atan((sy-oy)/(sx-ox)) into a4
put atan((sy-wy)/(sx-wx)) into a5
put atan((sy-ey)/(sx-ex)) into a6
if (sx-px) < 0 then add pi to a
if (sx-qx) < 0 then add pi to a2
if (sx-rx) < 0 then add pi to a3
if (sx-ox) < 0 then add pi to a4
if (sx-wx) < 0 then add pi to a5
if (sx-ex) < 0 then add pi to a6

a)
if r2 < 10 then put 1198 into course
if r < 10 then put 1198 into course
if r3 < 10 then put 1198 into course
if r4 < 10 then put 1198 into course
if r5 < 20 then put 1198 into course
if r6 < 20 then put 1198 into course

c)
put min(r,r2,r3,r4,r5,r6) into rmin
put 5*rmin^2 into inf

b)
if max(r,r2,r3,r4,r5,r6) > 1000 then put 1198 into course


add inf*q/((r)^2) *cos(a) to sx
add inf*q/((r)^2) *sin(a) to sy
add inf*(q2/((r2)^2))*cos(a2) to sx
add inf*(q2/((r2)^2))*sin(a2) to sy
add inf*q3/((r3)^2) *cos(a3) to sx
add inf*q3/((r3)^2) *sin(a3) to sy
add inf*q4/((r4)^2) *cos(a4) to sx
add inf*q4/((r4)^2) *sin(a4) to sy
add inf*q5/((r5)^2) *cos(a5) to sx
add inf*q5/((r5)^2) *sin(a5) to sy
add inf*q6/((r6)^2) *cos(a6) to sx
add inf*q6/((r6)^2) *sin(a6) to sy
if course > 1 then drag from round(sxx),round(syy) to round(sx),round(sy)
put sx into sxx
put sy into syy
end repeat
end repeat
end repeat

On to the show! Take me home!