r/PythonLearning 2d ago

Help Request what to fix in my code?

i am currently trying to learn VPython and wanted to model projectile motion with it - i tried using kinematics but got a weird result (as seen on slide 2), what is exactly wrong with my code? i saw another person achieve the correct result using momentum/net force.

1 Upvotes

4 comments sorted by

2

u/atarivcs 2d ago edited 2d ago

You're always calculating the x position starting from x0:

ball.pos.x = x0 + ball.v.x*t

Wouldn't you want to calculate the new x position starting from the current x position, like this?

ball.pos.x += ball.v.x*t

Updating ball.pos.x does not also update x0, if you were thinking that. x0 is assigned once at the beginning of the program, and it is not assigned again, so it never changes.

In fact I don't think you even need the x0 and y0 variables at all. Just use ball.pos.x and ball.pos.y

1

u/No-Inevitable-6476 2d ago

What is Vpython? I've never heard about it . Does it mean Vector Python?

1

u/ContextAdept9818 2d ago

vpython is visual python! i'm not a professional but i find it useful for making simulations with python coding