gpt4 book ai didi

python - 试图让两个质量相互绕行......出现奇怪的错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:31:52 25 4
gpt4 key购买 nike

基本上,我已经创建了质量,给了它们一定的速度和动量,我试图让它们利用重力彼此绕轨道运行(围绕它们的质心)。

from visual import *

earth = sphere(radius = 100000000)
newPlanet = sphere(pos = (3.84403*10**8, 0, 0), radius = 10000000)

earth.velocity = vector(0, 100, 0)
newPlanet.velocity = vector(0, 100, 0)

earth.mass = 2*10**30
newPlanet.mass = 1*10**30

earth.p = vector(0, earth.mass*earth.velocity, 0)
newPlanet.p = vector(0, newPlanet.mass*newPlanet.velocity, 0)

dt = 1000
r = newPlanet.pos.x
T = 1.296*10**6
G = 6.673*10**-11

while 1:
Fnet = G*((earth.mass*newPlanet.mass)/r**2)

earth.p += Fnet*dt
newPlanet.p += Fnet*dt

earth.velocity += (earth.p/earth.mass)*dt
newPlanet.velocity += (newPlanet.p/newPlanet.mass)*dt

earth.pos += earth.velocity*dt
newPlanet.pos += newPlanet.velocity*dt

t += 1

rate(100)

这是我遇到的错误:

Traceback (most recent call last):
File "Untitled", line 12
earth.p = vector(0, earth.mass*earth.velocity, 0)
Boost.Python.ArgumentError: Python argument types in
vector.__init__(vector, int, vector, int)
did not match C++ signature:
__init__(struct _object *, class cvisual::vector)
__init__(struct _object *)
__init__(struct _object *, double)
__init__(struct _object *, double, double)
__init__(struct _object *, double, double, double)

最佳答案

vector 将三个数字作为参数,如 vpython 文档所示 here

在您的作业 earth.p = vector(0, earth.mass*earth.velocity, 0) 中,earth.mass*earth.velocity 是一个矢量typeof(earth.mass*earth.velocity) 将指示而不是预期的数字。

因此出现错误消息,你确定你不是这个意思吗

earth.p = vector(0, earth.mass*mag(earth.velocity), 0)

earth.p = vector(0, earth.mass*earth.velocity.y, 0) 代替。

关于python - 试图让两个质量相互绕行......出现奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9346363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com