使用实际值时VPython轨道不正确

时间:2018-11-25 03:39:40

标签: python astronomy vpython

我正在尝试创建一个由三部分组成的模拟,其中包括太阳,火星和一个流氓行星,它们会飞过,这会影响火星的轨道。到目前为止,我在某种程度上类似于模拟。

引力常数大于应有的值,并且轨道半径不正确。火星在1.52 AU附近绕太阳运行,但在此程序中,它们之间的距离为9 AU。如果我对所有事物都使用正确的值,那么轨道将无法工作,尤其是当我将第23行的动量从(0,2,0)更改为(0,24100,0)时,轨道速度为24.1 km / s。

我在做什么错了?

from visual import *
from visual.controls import *
import math


scene = display(width=1200, height=1200)    #set animation window size
scene.autoscale = 0                         #disable zoom if orbit size increases


#constants
m1 = 1.989e30      #mass Sun
m2 = 6.39e23       #mass Mars
m3 = 1.898e27      #mass intruding object
G = 6.67e-7        #gravitational constant, supposed to be 6.67e-11 but doesn't work
AU = 1.496e11      #astronomical unit
R = 0.1            #object render size

T = 1000.00        #max run time
dt = 0.001         #run rate

#momenta
p1 = m1*vector(0,0,0)      #Sun
p2 = m2*vector(0,2,0)      #Mars
p3 = m3*vector(0,10,0)     #Intruder

p0 = m1*vector(0,0,0)      #zero vector to make something stationary



#object positions must be scaled down, but use correct for calculations
obj1 = sphere(pos=vector(-4.50,0), radius = R, color = color.orange, make_trail = True)         #Sun
obj2 = sphere(pos=vector(4.5,0), radius = R/3, color = color.red, make_trail = True)           #Mars
obj3 = sphere(pos=vector(10,-10), radius = R, color = color.white, make_trail = True)            #Intruder



t = 0
while t < T:

    rate(1000)    #change this to make animation faster


    #seperation vectors
    r12 = (obj2.pos - obj1.pos)*AU
    r21 = -r12
    r13 = (obj3.pos - obj1.pos)*AU
    r31 = -r13
    r23 = (obj3.pos - obj2.pos)*AU
    r32 = -r23


    #forces, norm = unit vector x/|x|, mag = magnitude |x|
    F12 = -G*m1*m2*norm(r12)/(mag(r12)**2)
    F21 = -F12
    F13 = -G*m1*m3*norm(r13)/(mag(r13)**2)
    F31 = -F13
    F23 = -G*m2*m3*norm(r23)/(mag(r23)**2)
    F32 = -F23

    #updating object positions
    obj1.pos = obj1.pos + p0*dt/m1       #Sun is stationary
    obj2.pos = obj2.pos + p2*dt/m2
    obj3.pos = obj3.pos + p3*dt/m3

    #updating momenta
    p1 = p1 + (F21 + F31)*dt
    p2 = p2 + (F12 + F32)*dt
    p3 = p3 + (F13 + F23)*dt

    t = t + dt

0 个答案:

没有答案