&引用;财产';pos&x27;必须是向量";运行VPython代码时出错
当我运行这段代码时,我得到一个错误“error:Property'pos'必须是一个向量”。我必须在某个地方写另一个向量吗?因为我在&引用;财产';pos&x27;必须是向量";运行VPython代码时出错,python,vpython,glowscript,Python,Vpython,Glowscript,当我运行这段代码时,我得到一个错误“error:Property'pos'必须是一个向量”。我必须在某个地方写另一个向量吗?因为我在 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),
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
改变
到
见文件
也来自文件
GlowScript VPython和VPython 7与经典VPython 6有何不同
·矢量必须表示为矢量(x,y,z)或矢量(x,y,z),而不是(x,y,z)。请在请求调试帮助时包含完整的错误回溯。您将速度定义为
对象,此时它是一个球体,而不是矢量。另外,不要使用object
作为变量名,它是Python的内置组件之一。
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)