Python 迈克尔逊-莫利实验返回错误时间值的模拟?

Python 迈克尔逊-莫利实验返回错误时间值的模拟?,python,vector,simulation,physics,vpython,Python,Vector,Simulation,Physics,Vpython,我正在尝试使用VPython模块创建一个模拟,如果存在“以太”,那么Michelson-Morley实验会产生什么结果。 出于某种原因,横向光传输到镜子和背面所用时间的打印值是不正确的,而纵向光的打印值是正确的,在systemV=10^7 m/s时(它意味着6.67037 x 10^-8,但我一直得到6.66668 x 10^-8,即使我的dt是10^-13,所以肯定不会产生如此大的误差) 从vpython导入* #背景 dt=10**-13 L=10#从玻璃到镜子的距离(光线经过的距离) s

我正在尝试使用VPython模块创建一个模拟,如果存在“以太”,那么Michelson-Morley实验会产生什么结果。 出于某种原因,横向光传输到镜子和背面所用时间的打印值是不正确的,而纵向光的打印值是正确的,在systemV=10^7 m/s时(它意味着6.67037 x 10^-8,但我一直得到6.66668 x 10^-8,即使我的dt是10^-13,所以肯定不会产生如此大的误差)


从vpython导入*
#背景
dt=10**-13
L=10#从玻璃到镜子的距离(光线经过的距离)
startPos=向量(0,0,0)
c=3*10**8#光速“相对于乙醚”
耳轴=0
L运行=0
运行=0
t=0
systemV=矢量(10,0,0)#地球通过“以太”的速度
lightv=矢量(c,0,0)-systemV#折射前的光速
scene.background=向量(1,1,1)
scene.range=L+2
scene.center=向量(5,0,0)
场景宽度=400
#模拟光
光线=球体(位置=矢量(startPos.x-L/2,0,0),颜色=矢量(0.5,0.5,0.8),半径=L/50,使光线折射前
t球=球体(位置=起始点,颜色=矢量(1,0.529,0.8),半径=光。半径,使_trail=假)#沿横臂移动的光
lBall=球体(位置=起始点,颜色=矢量(0.529,0.529,1),半径=光。半径,使_trail=假)#沿纵臂移动的光
#模拟装置
t镜子=盒子(位置=起始点+向量(0,L+T球半径,0),尺寸=向量(L*0.5,0.02,2))#横臂上的镜子
lMirror=box(pos=startPos+vector(L+tBall.radius,0,0),size=vector(0.02,L*0.5,2))#纵臂上的镜子
玻璃=长方体(位置=起始点,颜色=矢量(0,0,0),尺寸=矢量(L/3,L/3,2),不透明度=0.2)#将光线折射并分散到2
#按钮
def startEther():
全局运行、耳轴、LRUNING、t、systemV、lReturned、Tretured、tBallv、lBallv、vtballPythag、tBall、lBall、lightv、timeDiff、lTIme、tTime
运行=1
耳轴=0
L运行=0
t=0
systemV=向量(speedSlider.value,0,0)
lReturned=0
t返回=0
tBallv=向量(0,c,0)-systemV
lBallv=向量(c,0,0)-systemV
tBall.pos=startPos
lBall.pos=startPos
光位置=矢量(起始点x-L/2,0,0)
lightv=向量(c,0,0)-systemV#正确
#vtballPythag=sqrt(c**2+systemV.x**2)
时间=0
t时间=0
timeDiff=0
打印(“相对于乙醚的仪器速度={.9}”。格式(systemV.x),“m/s”)
按钮(text='start',bind=startEther)
#对于滑块
def调整速度():
speedSliderReadout.text=speedSlider.value/(10**7)
场景。将\u附加到\u标题(“\n\n”)
场景。将添加到标题(“通过乙醚的仪器速度/10^7 m/s=”)
speedSliderReadout=wtext(text='1')
速度滑块=滑块(左=10,最小=1*10**7,最大=2*10**7,步长=10**6,值=1*10**7,绑定=调整速度)
#主要
尽管如此:
速率(1/dt)
如果运行==1:#折射前的灯光正在移动
如果灯位置x小于0:
light.pos+=lightv*dt
elif灯位置x>=0,耳轴==0,L运行==0:
运行=0
耳轴=1
L运行=1
t=0
其他:
通过
如果耳轴==1:#横臂灯
如果tBall.pos.y>=L且Tretured==0:
tBallv=向量(0,-c,0)-systemV
tBall.pos+=tBallv*dt
Treturn=1
elif tReturned==1,tBall.pos.y=L,lReturned==0:
lBallv=向量(-c,0,0)-systemV
lBall.pos+=lBallv*dt
lReturned=1
elif lBall.位置x

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