简体   繁体   English

Vpython 错误:'float' object 没有属性'_x'

[英]Vpython Error: 'float' object has no attribute '_x'

I am writing a Vpython simulation for projectile motion and keep getting the error ('float' object has no attribute '_x') on this line(ball.vel.y = ball.vel.y + g*dt).我正在为射弹运动编写 Vpython 模拟,并在此行 (ball.vel.y = ball.vel.y + g*dt) 上不断收到错误消息(“浮动”object 没有属性“_x”)。 I have tried changing the values of ball.vel.y to an integer and changing g to an integer but the same error occurs.我尝试将 ball.vel.y 的值更改为 integer 并将 g 更改为 integer 但出现相同的错误。 Here is the code这是代码

from vpython import *
import math

ball=sphere(radius=0.1, color=color.red, pos=vector(0.1,0.1,0),make_trail=True)
floor=box(pos=vector(0,0,0), length=10, height=0.01, width=0.01)
g= vector(0,-9.8 ,0)
ball.vel=vector(10*cos(43),10*sin(43),0)
dt=0.1
t=0.0

while(ball.pos.y>-0.001):
    rate(100)
    t=t+dt
    ball.pos.x = ball.pos.x + ball.vel.x*dt
    ball.vel.y = ball.vel.y + g*dt
    ball.pos.y = ball.pos.y + ball.vel.y*dt

g is a vector, as is g*dt, but ball.vel.y is a scalar, and you can't add a vector to a scalar. g 是矢量,g*dt 也是,但 ball.vel.y 是标量,不能将矢量与标量相加。 It's unfortunate that the error message doesn't just say "You can't add a vector to a scalar".不幸的是,错误消息不只是说“您不能将矢量添加到标量”。 I note that if you reverse the two quantities the error message is a bit more understandable: TypeError: unsupported operand type(s) for +: 'vpython.cyvector.vector' and 'float'我注意到,如果您反转这两个数量,则错误消息更容易理解:TypeError: unsupported operand type(s) for +: 'vpython.cyvector.vector' and 'float'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基本的Vpython代码错误-“ TypeError:一元错误的操作数类型-:'tuple'” - Basic Vpython code error - “TypeError: bad operand type for unary -: 'tuple'” 春天不会振荡vpython - spring wont oscillate vpython 我得到一个 AttributeError: 'Particle' object has no attribute 'MomentumSum',如果有人能提供帮助,那就太好了,谢谢 - I get thrown a AttributeError: 'Particle' object has no attribute 'MomentumSum' , if someone could help that would be great, thanks 如何在 Glowscript/VPython 中模拟多个弹丸轨迹? - How to simulate multiple projectile trajectories in glowscript/VPython? Corona SDK-检查对象是否已停止移动 - Corona SDK - Check if object has stopped moving 冠冕:物理学,物体改变其(x,y) - CORONA : physics, object changes its (x,y) 我正在尝试使用vpython创建一个轨道模拟器,但是当我运行它时,我只会看到黑屏 - I'm trying to create an orbital simulator using vpython but when I run it I just get a black screen 我正在尝试使用vPython计算密钥的持续时间 - I'm trying to time how long a key is held down using vPython 如何使用Box2d使对象在特定高度上平稳地飞行或浮动? - How to make an object fly or float smoothly above a certain height using Box2d? 电晕物理学,检查对象何时不动及其x,y值 - Corona physiscs, check when an object is motionless and its x, y values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM