doubleslit.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """Simulation of the double slit experiment.
  2. (Any number of slits of any geometry can be added)
  3. Slit sources are placed on the plane shown as a thin grid"""
  4. # Can simulate the 'Arago spot', the bright point at the center of
  5. # a circular object shadow (https://en.wikipedia.org/wiki/Arago_spot).
  6. from vedo import *
  7. #########################################
  8. lambda1 = 680e-9 # red wavelength 680nm
  9. width = 10e-6 # slit width in m
  10. D = 0.1 # screen distance in m
  11. #########################################
  12. # create the slits as a set of individual coherent point-like sources
  13. n = 10 # nr of elementary sources in slit (to control precision).
  14. slit1 = list(zip([0]*n, np.arange(0,n)*width/n, [0]*n)) # source points inside slit1
  15. slit2 = list(slit1 + np.array([1e-5, 0, 0])) # a shifted copy of slit 1
  16. slits = slit1 + slit2
  17. # slits += list(slit1 + array([-2e-5, 1e-5, 0])) # add another copy of slit1
  18. # slits = [(cos(x)*4e-5, sin(x)*4e-5, 0) for x in arange(0,2*np.pi, .1)] # Arago spot
  19. # slits = Grid(s=[1e-4,1e-4], res=[9,9]).points # a square lattice
  20. screen = Grid(pos=[0, 0, -D], s=[0.1,0.1], lw=0, res=[200,50]).wireframe(False)
  21. # Compute the image on the far screen
  22. k = 0.0 + 1j * 2 * np.pi / lambda1 # complex wave number
  23. norm = len(slits) * 5e5
  24. amplitudes = []
  25. verts = screen.points
  26. for i, x in enumerate(verts):
  27. psi = 0
  28. for s in slits:
  29. r = mag(x - s)
  30. psi += np.exp(k * r) / r
  31. psi2 = np.real(psi * np.conj(psi)) # psi squared
  32. amplitudes.append(psi2)
  33. verts[i] = x + [0, 0, psi2 / norm]
  34. screen.cmap("hot", amplitudes)
  35. plt = Plotter(title="The Double Slit Experiment", axes=9, bg="black")
  36. plt += [screen, __doc__]
  37. plt += Points(np.array(slits) * 200).color("w") # slits scale magnified by factor 200
  38. plt += Grid(s=[0.1,0.1], res=[6,6],).color("w",0.1)
  39. plt += Line([0, 0, 0], [0, 0, -D],).color("w",0.1)
  40. plt += Text3D("source plane", pos=[-0.04, -0.05, 0], s=0.002).c("gray")
  41. plt += Text3D("detector plane D = "+str(D)+" m", pos=[-.04,-.05,-D+.001], s=.002).c("gray")
  42. plt.show(zoom=1.15).close()