I am trying to create a simulation using the module VPython of what would be expected from the Michelson-Morley experiment if an 'ether' existed. for some reason, the printed value for the time taken for the transverse light to travel to the mirror and back is incorrect whereas the one for the longitudinal light is correct, at systemV = 10^7 m/s (it is meant to be 6.67037 x 10^-8 but i keep getting 6.66668 x 10^-8, even though my dt is 10^-13 so surely that cannot create such a big error)
from vpython import *
#settings
dt = 10**-13
L = 10 #distance from glass to mirror (distance travelled by light)
startPos = vector(0,0,0)
c=3*10**8 #speed of light 'relative to the ether'
trunning = 0
lrunning = 0
running=0
t=0
systemV = vector (10,0,0) #velocity of the earth through the 'ether'
lightv=vector(c,0,0)-systemV #speed of light before refraction
scene.background=vector(1,1,1)
scene.range = L+2
scene.center=vector(5,0,0)
scene.width=400
#simulating light
light = sphere(pos=vector(startPos.x-L/2,0,0), color=vector(0.5,0.5,0.8), radius=L/50, make_trail=False) #light before refraction
tBall = sphere(pos=startPos, color=vector(1,0.529,0.8), radius=light.radius, make_trail=False) #light travelling along transverse arm
lBall = sphere(pos=startPos, color=vector(0.529,0.529,1), radius=light.radius, make_trail=False) #light travelling along longitudinal arm
#simulating apparatus
tMirror = box(pos=startPos+vector(0,L+tBall.radius,0), size=vector(L*0.5,0.02,2)) #mirror on transverse arm
lMirror = box(pos=startPos+vector(L+tBall.radius,0,0), size=vector(0.02,L*0.5,2)) #mirror on longitudinal arm
glass = box(pos=startPos, color=vector(0,0,0), size=vector(L/3,L/3,2), opacity=0.2) #the glass block that refracts and disperses light into 2
#for the button
def startEther():
global running, trunning, lrunning, t, systemV, lReturned, tReturned, tBallv, lBallv, vtballPythag, tBall, lBall, light, lightv, timeDiff, lTIme, tTime
running = 1
trunning = 0
lrunning = 0
t=0
systemV = vector (speedSlider.value,0,0)
lReturned = 0
tReturned = 0
tBallv = vector(0,c, 0)-systemV
lBallv = vector(c,0,0)-systemV
tBall.pos=startPos
lBall.pos=startPos
light.pos=vector(startPos.x-L/2,0,0)
lightv=vector(c,0,0)-systemV #correct
#vtballPythag = sqrt(c**2+systemV.x**2)
lTime = 0
tTime = 0
timeDiff = 0
print("speed of apparatus relative to ether = {:.9}".format(systemV.x), "m/s")
button(text='start', bind=startEther)
#for the slider
def adjustSpeed():
speedSliderReadout.text = speedSlider.value/(10**7)
scene.append_to_caption("\n\n")
scene.append_to_caption(" Apparatus Speed through ether / 10^7 m/s = ")
speedSliderReadout = wtext(text='1')
speedSlider=slider(left=10, min=1*10**7, max=2*10**7, step=10**6, value=1*10**7, bind=adjustSpeed)
#main
while True:
rate(1/dt)
if running ==1: #light before refraction is moving
if light.pos.x < 0:
light.pos += lightv*dt
elif light.pos.x >=0 and trunning==0 and lrunning==0:
running=0
trunning=1
lrunning=1
t=0
else:
pass
if trunning==1: #transverse arm light
if tBall.pos.y >= L and tReturned==0:
tBallv = vector(0,-c,0)-systemV
tBall.pos += tBallv * dt
tReturned = 1
elif tReturned ==1 and tBall.pos.y<=0:
tTime = t
print ("time taken for transverse to travel to & from glass = {:.20f}".format(tTime))
trunning = 0
else:
tBall.pos += tBallv * dt
if lrunning==1: #longitudinal arm light
if lBall.pos.x >= L and lReturned==0:
lBallv = vector(-c,0,0)-systemV
lBall.pos += lBallv * dt
lReturned = 1
elif lBall.pos.x <= 0 and lReturned==1:
lTime = t
print ("time taken for longitudinal to travel to & from glass = {:.20f}".format(lTime))
lrunning=0
timeDiff = lTime-tTime
print("time difference = {:.20f}".format(timeDiff))
else:
lBall.pos += lBallv * dt
t += dt