from __future__ import division from visual import * print """ Ruth Chabay Spring 2001 Click to start waves moving. """ scene.x = scene.y = 0 scene.width = 1000 scene.height = 600 scene.forward = (0,-1,-2) scene.background = color.white ihat=vector(1,0,0) lamb = 1e-1 ##1e-10 c = 3e8 omega = 2*pi*c/lamb d = 2*lamb ## slit spacing Evec1 = [] Evec2 = [] dist_to_screen = 4.0*lamb ## dist to screen scene.center = (dist_to_screen*.65,-d/2.,0) ds = lamb/20. dt = lamb/c/100. E0 = lamb/3.0 screen = curve(pos = [(dist_to_screen,0,0),(dist_to_screen,0,2*d)], color=(.6,.6,.6)) slit1 = vector(0, 0, -d/2.) ## coord of slit 1 slit2 = vector(0, 0, d/2.) ## coord of slit 2 ## found by search: see interf02_loc.py max1 = vector(dist_to_screen,0,0) max2 = vector(dist_to_screen,0,0.24) min1 = vector(dist_to_screen,0,0.108) ## or z=0.11 #### vectors from slits to max2: ##r1 = max2 - slit1 ##r2 = max2 - slit2 ##r1maxarr = arrow(pos=slit1, axis=(max2-slit1), color=color.magenta, ## shaftwidth = lamb/80.) ##r2maxarr = arrow(pos=slit2, axis=(max2-slit2), color=color.cyan, ## shaftwidth = lamb/80.) ## vectors from slits to min1: r1 = min1 - slit1 r2 = min1 - slit2 # vectors from slits to loc. on screen ##r1arr=arrow(pos=slit1,axis=r1, color=color.red, shaftwidth=lamb/60.) dr1 = ds*norm(r1) ##r2arr=arrow(pos=slit2, axis=r2, color=color.green, shaftwidth=lamb/60.) dr2 = ds*norm(r2) rr1 = slit1 + vector(0,0,0) ## current loc along wave 1 rr2 = slit2 + vector(0,0,0) ## current loc along wave 2 i1 = None i2 = None ## create first wave ct = 0 while ct < 120: ea = arrow(pos=rr1, axis=(0,E0*cos(2*pi*mag(rr1-slit1)/lamb),0), color=color.red, shaftwidth=lamb/40.) ba = arrow(pos=rr1, axis=(0,0,0), color=(.4,.4,1), shaftwidth=lamb/40., visible=0) ea.B = ba if abs(ea.x - dist_to_screen) < 0.002 and i1==None: i1 = ea ## i1.visible = 0 else: Evec1.append(ea) rr1 = rr1 + dr1 ## arrow(pos=rr1,axis=dr1,color=color.red, shaftwidth=lamb/60.) ct = ct + 1 #### create second wave ct = 0 while ct < 100: ea = arrow(pos=rr2, axis=(0,E0*cos(2*pi*mag(rr2-slit2)/lamb),0), color=(1.,.6,0), shaftwidth=lamb/40.) ba = arrow(pos=rr2, axis=(0,0,0), color=color.cyan, shaftwidth=lamb/40., visible=0) ea.B = ba if abs(ea.x - dist_to_screen) < 0.002 and i2==None: i2 = ea else: Evec2.append(ea) rr2 = rr2 + dr2 ct = ct + 1 ### ##print i1.color,i2.color ### scene.autoscale = 0 scene.mouse.getclick() i1.visible = 0 ##i2.color = color.black t=0.0 while 1: rate(50) if scene.mouse.clicked: ## toggle vis of mag field vectors scene.mouse.getclick() for a in Evec1 + Evec2 : a.B.visible = not(a.B.visible) i2.B.visible = not(i2.B.visible) t = t+dt for ea in Evec1: ea.axis = (0,E0*cos(omega*t - 2*pi*mag(ea.pos-slit1)/lamb),0) ea.B.axis = cross(ihat,ea.axis)*.7 for ea in Evec2: ea.axis = (0,E0*cos(omega*t - 2*pi*mag(ea.pos-slit2)/lamb),0) ea.B.axis = cross(ihat,ea.axis)*.7 # superposition sum = E0*cos(omega*t - 2*pi*mag(i1.pos-slit1)/lamb)+E0*cos(omega*t - 2*pi*mag(i2.pos-slit2)/lamb) i2.axis = vector(0,sum,0) ## if mag(sum) < 0.1*E0: ## i2.axis = vector(0,0,0) ## else: ## i2.axis = sum ## print mag(sum) i2.B.axis = cross(i2.axis,ihat)*.7 ## ## ##