## 3D Charge Simulator

Paste the code at the end of this post here:

https://www.beautifulmathuncensored.de/static/GlowScript/GlowScript.html

And press “Run”.

Edit “pos” (position), “velocity”, “charge” and “mass” parameters to simulate a different set of charged particles.
Add a sphere with all the parameters (followed by a “,”) to add an additional charged particle to the simulation.

I hope people will play around and have fun!

Code:

```# from math import *
# from visual import *
# from visual.graph import *
from vpython import *
# import vpython

scene.fullscreen = True

G = 10

# edit initial conditions here
##########
spheres = [
]

#print(spheres[0].a)

#print(len(spheres))

def acceleration1on2(sphere2,sphere1):
r = sphere2.pos - sphere1.pos
r_mag = mag(r)
normal_r = norm(r)
g = ((G*sphere1.charge*sphere2.charge)/pow(r_mag,2))/sphere2.mass*normal_r
#print(g)
return g

t = 0
dt = .01
while 1:
rate(100)
for i in spheres:
i.a = vector(0,0,0)
soi = vector(0,0,0)
for j in spheres:
if i!=j:
i.a = i.a + acceleration1on2(i,j)

for i in spheres:
#print(i.velocity)
i.velocity = i.velocity + i.a *dt
i.pos = i.pos+i.velocity*dt
#print(i.a)
i.trail.append(pos=i.pos)

scene.center=vector(spheres[0].pos.x,spheres[0].pos.y,spheres[0].pos.z)

# print(i.a)

```