我正在尝试使用 vpython 创建一个轨道模拟器,但是当我 运行 它时,我只是得到一个黑屏
I'm trying to create an orbital simulator using vpython but when I run it I just get a black screen
我使用了一个 youtube 视频作为我的代码的基础,并对其进行了调整以包含 类 和对象。视频中的原始代码完美运行。 我的代码版本 returns 黑屏,即使在尝试修复它时,我最幸运的是两个对象显示不动。 我还在 glowscript IDE 和 winpython 上尝试过 运行。 感谢任何能提供帮助的人!
from vpython import *
class Planet:
def __init__(self, radius, colour, mass, x, y, z, vx, vy, vz):
self.radius = int(radius)
self.colour = colour
self.mass = int(mass)
self.x = int(x)
self.y = int(y)
self.z = int(z)
self.vx = int(vx)
self.vy = int(vy)
self.vz = int(vz)
def run_planet(self):
r = self.radius
c = self.colour
px = self.x
py = self.y
pz = self.z
vx = self.vx
vy = self.vy
vz = self.vz
p = sphere(pos = vec(px, py, pz), radius = r, color = color.white, make_trail = True)
v = vec(vx, vy, vz)
for i in range(1000):
rate(100)
p.pos = p.pos + v
dist = (p.pos.x**2 + p.pos.y**2 + p.pos.z**2)**0.5
RadialVector = (p.pos - sun.pos)/dist
Fgrav = -(6.674*10**11)*self.mass*(1.989*10**30) * RadialVector/dist**2
v = v + Fgrav
p.pos += v
if dist <= sun.radius: break
###############################################################################
sun = sphere(pos = vec(0,0,0), radius = 100, color = color.orange)
p1 = Planet(10, "blue", 20, -200, 0, 0, 0, 0, 5)
p1.run_planet()
视频中的原始代码:
sun = sphere(pos = vec(0,0,0), radius = 100, color = color.orange)
earth = sphere(pos = vec(-200,0,0), radius = 10, color = color.white, make_trail = True)
earthv = vec(0,0,5)
for i in range(10000000):
rate(100)
earth.pos = earth.pos + earthv
dist = (earth.pos.x**2 + earth.pos.y**2 + earth.pos.z**2)**0.5
RadialVector = (earth.pos - sun.pos)/dist
Fgrav = -10000 * RadialVector/dist**2
earthv = earthv + Fgrav
earth.pos += earthv
if dist<= sun.radius: break
Ps: 任何物理修正也将不胜感激!
太阳(中心)和行星(中心)之间的距离只有 200 米,所以计算出的力是巨大的,新的 v 是 10 到 38 的数量级,所以马上这颗行星离太阳太远,以至于相机向后移动以试图显示整个场景,但由于物体现在离太阳太远,屏幕呈现黑色。