This page describes a “pitched ball trajectory calculator”. I hope to create a practical and useful model that represents the flight path of a ball within normal play conditions. Eventually, this will become a general simulation of the ball trajectory, meaning it will be suitable for batted balls or even throws between defensive players. My end goal is to create a web-based app into which you can input some conditions and see what the ball does.
Thank you to Professor Alan Nathan for letting me use his Excel sheet as the foundation of my code and for spending the time to answer my questions. You can go to his website here and I would encourage you to do so. There is a ton of stuff in these spreadsheets that is very interesting. He has a whole website about the physics of baseball.
The program, which I’m calling UMBA, is a Python script designed to take 11 initial conditions and predict the path of the ball. The initial conditions are all at the moment of release. These include position (x, y, z), velocity (u, v, w), and the spin rate (ωx, ωy, ωz) and seam orientation in cartesian space. The initial velocities can be defined in terms of initial total velocity, launch angle, and heading angle. The spin rate can also be described by a spin rate, tilt, and gyro.
From these initial conditions, and using various aerodynamic models of the baseball, we can use the computer to estimate for the trajectory. The trickiest part is modeling the aerodynamics. There are theoretical models that are based on fundamental theories of fluid dynamics. There are also empirical models based and experimental data. The empirical models tend to be more accurate but are specific to one set of conditions. Theoretical models are more likely to cover a large range of conditions but may not be as accurate. This is especially true in odd cases such as a seam shifted wake.
A good example of this is the Magnus model used in this early code. A 2-seam fastball and a 4-seam fastball both thrown exactly the same besides seam orientation will behave the same according to the program. The experience of pitchers and serious fans shows this to be false and that, indeed, seam orientation does matter. I built this early code to be expandable and modifiable so that, as better models become available, I can alter the code can to include them.
The heart of this program is a 4th order Runge-Kutta (RK4) numerical integration method used to solve a system of differential equations. this is one of the key differences between my trajectory calculator and Professor Nathan’s excel sheets. Professor Nathan’s sheets use the kinematic equations of motion. The kinematic equations are probably sufficient given the error contained in the various drag and lift models used. I used the RK4 method as I would like the code to be as updatable as possible. As the models are refined and corrected an RK4 method will never cause any significant error.
I note that Professor Nathan uses an RK4 method for a FORTRAN version of his trajectory calculator.
There is a link here that will allow you to download my code and run it for yourself. You can run it with whatever Python software you want. If you are new to Python I would recommend downloading Anaconda and running the Spyder i.d.e. It is free and will include all the libraries I use. Furthermore, I use Spyder so if you have some snafus while running the code I will be better able to help.
After inputting your initial conditions the program will output a list of results. For now, these include:
Initial State
position
velocity
spin
spin efficiency
Decision Point State
position
velocity
Final State
position
velocity
spin
spin efficiency
approach angles (both descent and heading)
change in position after the decision point
Totals
Flight time
vertical break
horizontal break
number of revolutions
Three plots are created showing the path of the ball. The green dot shows the release point the yellow dot shows the decision point (about 200 ms after release where the batter has to say keep swinging or stop) and the red dot shows the final location of the ball. when it passes the plat, hits the ground, or if the code time hits 10 seconds.
Please let me know in the comments what changes you would like to see especially in terms of additional inputs or outputs (things like a strike zone or initial spin efficiency). If you have coding experience and see something that might make this code better please let me know and I will do my best to incorporate it.
You must be logged in to post a comment.