模拟轨道 [英] Simulating Orbits

查看:163
本文介绍了模拟轨道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试模拟绕太阳行进的地球,其中地球的速度由其与原点和水平面的夹角确定.我通过创建对三角形O_correction(x,y)使用tanh(相对/相邻)规则的函数来做到这一点.问题是它不是圆形轨道而是螺旋形上升,我不确定为什么.

So I'm trying to simulate the earth travelling around the sun where the velocity of the earth is determined by the angle its at to the origin and the horizontal. I did this by creating a function that uses tanh (opposite/adjacent) rule for triangles, O_correction(x,y). The problem is that instead of a circular orbit its instead spiralling out and I'm not sure why.

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

非常感谢您的帮助, 欢呼声

Would very much appreciate some help, Cheers

推荐答案

我不懂python,但我懂物理.

I don't know python, but I know physics.

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

At each step you move the Earth a fixed distance along a tangent to the orbit, rather than along the orbit itself. That gives you an outward spiral (which will actually get less severe as you go out).

尝试使时间增量变小(例如,将位置调整值除以100),螺旋效应将变小.

Try making the time increment smaller (e.g. by dividing the position adjustment by 100), and the spiral effect will get much smaller.

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

If you want to do better than that, you'll need a different formula. You could either impose a circular orbit, or do something based on conserved quantities (which requires a considerable understanding of basic physics).

这篇关于模拟轨道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆