【问题标题】:Create simulation of Earth revolving around sun in vpython在vpython中创建地球绕太阳旋转的模拟
【发布时间】:2018-03-28 20:58:32
【问题描述】:

我必须创建一个地球围绕太阳旋转的简单模拟。我不能使用球坐标,我必须使用引力能量和速度方程到目前为止我有这个:

earth = sphere (color = color.green, radius = 10**6)
sun = sphere (color = color.yellow, radius = 10**7)
earth.mass = 5.972*10**24 
sun.mass=1.989*10**30
d=1.496*10**8
v=(2*math.pi*d)/(3.154*10**7)
earth.velocity = vector(0.0, 0.0, -1*v)
earth.pos = vector(d, 0, 0)
sun.pos = vector(0,0,0)

dt = 50000
t = 0.0

P=0    
while True:
rate(400)
    f=(6.667*10**.11)*((earth.mass*sun.mass)/d**2)
    P = P + f*dt
    earth.velocity = P/earth.mass
    earth.pos = earth.pos + earth.velocity*dt
    t=t+dt

我不知道我是否在物理方面或编码方面遗漏了一些东西,但是当我运行它时,什么也没有出现。提前致谢!

【问题讨论】:

    标签: physics vpython


    【解决方案1】:

    两个问题:您的速率语句必须缩进,并且随着动量 P 初始化为 0,地球应该落入太阳。

    【讨论】:

      猜你喜欢
      • 2014-02-02
      • 2015-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 2021-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多