gpt4 book ai didi

python - "Property ' pos ' must be a vector"运行VPython代码时出错

转载 作者:太空狗 更新时间:2023-10-30 01:19:08 25 4
gpt4 key购买 nike

当我运行这段代码时,出现错误“错误:属性‘pos’必须是一个向量。”我必须在某处写另一个向量吗?因为我在

写了 vector
grav_force = vector(0,-object.mass*grav_field,0)

这是我的全部代码

GlowScript 2.7 VPython

from visual import *

display(width = 1300, height = 1000)

projectile = sphere(pos = (-5,0,0),
radius = 0.1,
color = color.red,
make_trail = True)

projectile.speed = 3.2 # Initial speed.
projectile.angle = 75*3.141459/180 # Initial angle, from the +x-axis.

projectile.velocity = vector(projectile.speed*cos(projectile.angle),
projectile.speed*sin(projectile.angle),
0)

projectile.mass = 1.0
grav_field = 1.0

dt = 0.01
time = 0

while (projectile.pos.y >=0):
rate(100)

# Calculate the force.
grav_force = vector(0,-projectile.mass*grav_field,0)

force = grav_force

# Update velocity.
projectile.velocity = projectile.velocity + force/projectile.mass * dt

# Update position.
projectile.pos = projectile.pos + projectile.velocity * dt

# Update time.
time = time + dt

最佳答案

改变

projectile = sphere(pos = (-5,0,0), radius = 0.1,color = color.red, make_trail = True)

projectile = sphere(pos = vector(-5,0,0), radius = 0.1, color = color.red, make_trail = True)

查看文档

http://www.glowscript.org/docs/VPythonDocs/sphere.html

也来自文档

GlowScript VPython 和 VPython 7 与经典 VPython 6 有何不同

· 向量必须表示为 vector(x,y,z) 或 vec(x,y,z),而不是 (x,y,z)。

关于python - "Property ' pos ' must be a vector"运行VPython代码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49390121/

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