Python Forum
Numerically determining the highest a ball travels when shot straight up
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numerically determining the highest a ball travels when shot straight up
#1
Hi all, I'm very new to python and I have no prior experience with other coding languages, so my main issues are with the formatting and finding the appropriate vocabulary. 

My goal is to determine the maximum height a ball reaches when thrown straight up.  I already wrote the code for the visual of the ball, but I don't know how to find and display a maximum value.  Any other advice or suggestions in regards to the code I already have would also be greatly appreciated.

Thanks!  Smile

from visual import *

myuniv = display(range = vector(3,3,3))

So = vector(0,1,0)
Vo = vector(0,6,0)
a = vector(0,-9.8,0)
s = vector(0,2,0)

dt = 0.1
t = 0.0

ball = sphere(pos = s, radius = 0.25, color = color.cyan)

while s.y > -2.0:
    rate(25)
    s = .5*a*t**2 + Vo*t + So
    v = a*t + Vo
    t = t + dt
    ball.pos = s
    ballghost = sphere(pos = s, radius = .2)
Reply
#2
I'm guessing s is the current height, since ball.pos = s.  In that case, just keep track of s.

Something like
max_pos = 0
while s.y > -2.0:
   s = #... calculate s
   if s > max_pos:
       max_pos = s
Reply
#3
Thanks! This worked out perfectly.  I wasn't sure how to set up an "if" statement before.  Big Grin
Reply
#4
Was you get is not the maximum height of the ball, but the maximum height you compute, and the accuracy therefore depends on the size of your samples. Getting the real value isn't that difficult (t for which v==0 so tmax=-Vo/a).
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Fit straight line to pandas time series data with semilog plot schniefen 2 1,500 Mar-10-2023, 01:08 PM
Last Post: jefsummers
  Determining the Percentage of Voter Population Than999 5 3,866 Dec-29-2019, 09:37 AM
Last Post: DeaD_EyE
  Methods that return the highest score from the list erfanakbari1 7 7,053 Mar-26-2019, 08:32 PM
Last Post: aankrose
  Ball bouncing down a ramp Envyiae 2 2,146 Jan-31-2019, 08:02 PM
Last Post: marienbad
  how to get the highest monthly average temperature? nikhilkumar 2 6,949 Jul-25-2017, 02:33 PM
Last Post: DeaD_EyE
  Returning the highest value out of 3 values ComputerSkillet 2 3,797 Apr-28-2017, 03:16 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020