【发布时间】:2021-07-21 04:47:06
【问题描述】:
我尝试过可视化太阳系的轨道,然后使用 vpython 库包含一个系外行星轨道。
它运行良好,但在程序开始时,有时轨道会跳过它们的圆周运动,而是跳到轨道中的不同位置,然后继续。行星轨迹留下锋利的边缘并穿过其他轨道。
我已上传问题的屏幕截图以显示 -
我在下面附上了我的代码,如果可能的话,有人可以帮我解决这个问题吗?非常感谢所有帮助,谢谢。
(为代码道歉,我正在学习,我正在努力改进它)
## Constants
# Radii:
starrad = 696.34e6
exoplanetrad = 3.8e6
mercuryrad = 2.44e6
venusrad = 6.05e6
earthrad = 6.38e6
marsrad = 3.4e6
# Position:
exoplanetpos = vector((8e9+starrad), 0, 0)
mercurypos = vector((5.79e9+starrad), 0, 0)
venuspos = vector((1.082e10+starrad), 0, 0)
earthpos = vector((1.496e10+starrad), 0, 0)
marspos = vector((2.279e10+starrad), 0, 0)
# Orbital Periods (Days):
exoplanetperiod = 170
mercuryperiod = 88
venusperiod = 224.7
earthperiod = 365.2
marsperiod = 687
# CHZ Attributes
chz_inner = ((0.75*mag(earthpos)) + starrad)
chz_outer = ((1.7*mag(earthpos)) + starrad)
chz_thickness = (0.009*mag(earthpos))
# Time
t = 0
deltat = 0.1
# Scene and Lights
#scene.autoscale = 0 # Removes autoscaling for better visuals
star_light = local_light(pos=vector(0,0,0), color=color.white, visible = True)
## Objects
star=sphere(color=color.orange,pos=vec(0,0,0),radius=starrad, emissive=True, texture = "http://i.imgur.com/yoEzbtg.jpg")
exoplanet=sphere(color=color.cyan,pos=exoplanetpos,radius=exoplanetrad, shininess=10, make_trail=True)
mercury=sphere(color=color.gray(0.75),pos=mercurypos,radius=mercuryrad, shininess=10, make_trail=True, opacity = 0.5)
venus=sphere(color=color.gray(0.75),pos=venuspos,radius=venusrad, shininess=10, make_trail=True, opacity = 0.5)
earth=sphere(color=color.gray(0.75),pos=earthpos,radius=earthrad, shininess=10, make_trail=True, opacity = 0.5)
mars=sphere(color=color.gray(0.75),pos=marspos,radius=marsrad, shininess=10, make_trail=True, opacity = 0.5)
ring1 = ring(pos= vec(0,0,0), axis = vec(0,1,0), radius = chz_inner, thickness = chz_thickness, color = color.green, opacity = 0.75)
ring2 = ring(pos= vec(0,0,0), axis = vec(0,1,0), radius = chz_outer, thickness = chz_thickness, color = color.red, opacity = 0.75)
## Labels
star_label = label(pos=star.pos,
text='Star', xoffset=10,
line = False, yoffset=10, height=12,
border=3, font='sans')
exoplanet_label = label(pos=exoplanet.pos,
text='Exoplanet', xoffset=10,
line = False, yoffset=10, height=12,
border=3, font='sans')
mercury_label = label(pos=mercury.pos,
text='Mercury', xoffset=10,
line = False, yoffset=10, height=12,
border=3, font='sans')
venus_label = label(pos=venus.pos,
text='Venus', xoffset=10,
line = False, yoffset=10, height=12,
border=3, font='sans')
earth_label = label(pos=earth.pos,
text='Earth', xoffset=10,
line = False, yoffset=10, height=12,
border=3, font='sans')
ring_label = label(pos=(ring1.pos+vector(0, 0, ring1.radius)),
text='CHZ Inner', xoffset=2,
line = False, yoffset=10, height=12,
border=3, font='sans')
ring_label2 = label(pos=(ring2.pos+vector(0, 0, ring2.radius)),
text='CHZ Outer', xoffset=2,
line = False, yoffset=10, height=12,
border=3, font='sans')
## Graphs
gd = graph(width=635, height=600, xtitle='Time', ytitle='Position',
foreground=color.gray(0.5), background=color.white,
xmax=20, xmin=0, ymax=6e10, ymin=-6e10)
g1 = gcurve(color=color.red)
g2 = gcurve(color=color.cyan) # a graphics curve
while True:
rate(100)
t = t + deltat
star.rotate(angle=(2*3.14159/365), axis=vector(0,1,0), origin=vector(0,0,0))
exoplanet.rotate(angle=(2*3.14159/exoplanetperiod), axis=vector(0,1,0), origin=vector(0,0,0))
mercury.rotate(angle=(2*3.14159/mercuryperiod), axis=vector(0,1,0), origin=vector(0,0,0))
venus.rotate(angle=(2*3.14159/venusperiod), axis=vector(0,1,0), origin=vector(0,0,0))
earth.rotate(angle=(2*3.14159/earthperiod), axis=vector(0,1,0), origin=vector(0,0,0))
mars.rotate(angle=(2*3.14159/marsperiod), axis=vector(0,1,0), origin=vector(0,0,0))
g1.plot((t, exoplanet.pos.z))
g2.plot((t, exoplanet.pos.x))
【问题讨论】:
-
直接发布您的图片,用户可以编辑您的帖子以嵌入它
-
我已经通过堆栈溢出直接发布添加了图像,希望可以吗?
标签: python vpython orbital-mechanics