试图让两个质量彼此绕轨道运行......出现奇怪的错误

发布于 2025-01-06 14:05:08 字数 1384 浏览 4 评论 0原文

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

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)

Basically, I've created the masses, gave them some velocity and momentum, and I'm trying to make them orbit each other (around their center of mass) using the force from gravity.

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)

This is the error I'm getting:

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少情深 2025-01-13 14:05:08

矢量采用三个数字作为参数,如 vpython 文档此处所示

在您的作业中 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) 代替。

vector takes three numbers as arguments as shown by vpython documentation here

In your assignment earth.p = vector(0, earth.mass*earth.velocity, 0), earth.mass*earth.velocity is a vector as typeof(earth.mass*earth.velocity) will indicate and not a number as expected.

Hence the error message, are you sure you didn't mean

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

or earth.p = vector(0, earth.mass*earth.velocity.y, 0) instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文