【问题标题】:Simulating Orbits模拟轨道
【发布时间】:2017-07-07 19:48:56
【问题描述】:

所以我试图模拟地球绕太阳运行,其中地球的速度取决于它与原点和水平面的角度。我通过创建一个对三角形使用 tanh(相反/相邻)规则O_correction(x,y) 的函数来做到这一点。问题是它不是一个圆形轨道而是螺旋出来的,我不知道为什么。

scene = canvas()
scene.background = color.white


O = 0
ball = sphere(pos=vector(10,0,0), radius=0.1, color=color.blue)

x = ball.pos.x
y = ball.pos.y

def O_correction(x,y):
    O = math.atan((((y)**2)**0.5)/(((x)**2)**0.5))
    answer = O
    if x >= 0 and y >= 0:
        answer = O
    if x < 0 and y >= 0:
        answer = pi - O
    if x <= 0 and y < 0:
        answer = O + pi
    if x > 0 and y < 0:
        answer =pi*2 - O     
    return answer

t =0
while t < 100:
    x = ball.pos.x
    y = ball.pos.y
    print = (float(O_correction(x,y))
    print = ((x**2) + (y**2))**0.5)
    ball.pos.x -= sin(O_correction(x,y))
    ball.pos.y += cos(O_correction(x,y))
    print(" ")
    t += 1

非常感谢一些帮助, 干杯

【问题讨论】:

  • 这不能回答您的问题,但我认为您可以使用atan2 而不是atan 而不是atan

标签: python-3.x vpython orbital-mechanics


【解决方案1】:

我不懂python,但我懂物理。

在每一步中,您都会将地球沿轨道的切线移动固定距离,而不是沿轨道本身移动。这会给你一个向外的螺旋(实际上随着你出去,它会变得不那么严重)。

尝试将时间增量变小(例如将位置调整除以 100),螺旋效应会变得更小。

如果您想做得更好,您将需要一个不同的公式。你可以施加一个圆形轨道,或者做一些基于守恒量的事情(这需要对基础物理学有相当的了解)。

【讨论】:

  • 是的,这是有道理的,我没有考虑增量之间的时间。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多