We love modeling and simulation at Modelon, and we have several avid baseball fans as well with strong rooting interests for the Atlanta Braves, Detroit Tigers, Boston Red Sox, and Minnesota Twins. I recently saw this post from Wired that showed the impact of air density on batted ball travel. The authors included some Python code that calculated the baseball trajectory subject to an initial velocity and launch angle (data that is now much easier to obtain with MLB’s new Statcast capability) and resistance due to air drag.

Since we do physical modeling with Modelica, I figured it would be interesting to build the same model in Modelica (why let the Python folks have all the fun, right?). So, I dipped into the Modelica.Multibody library (and I’m mostly a thermofluid guy so watch out as I’m dangerous now!!) to build the simple model of the baseball flight dynamics shown below. Since it is easy to add models in Modelica, I also implemented the model based on the references in the Wired article to calculate the fluid density as a function of temperature and relative humidity. I also extended that model with a calculation of the ambient pressure as a function of elevation. So now we can easily calculate the density as a function of location and weather conditions.

To illustrate the wide range of differences, let’s compare a cold spring day in Detroit, Michigan in April (51 degrees Fahrenheit, 65% relative humidity, 600 ft above sea level) with a warm summer day in Denver, Colorado (89 degrees Fahrenheit, 47% relative humidity, 5279 ft above sea level). As shown in the plot below, there is roughly 43.5 ft difference in travel at the same initial ball launch velocity (49.5 m/s) and angle (56 degrees). It is good to be a hitter in Colorado (not to mention the fact that curve balls don’t break as well, etc.)!!

Since we are using the Multibody library in Modelica, it is very easy to animate the ball trajectory. The video below shows the animation of the two simulations together from Dymola. The model is 3D, but the animation view has been set to visualize only in two dimensions. The size of the arrow represents the total drag force acting on the ball. It is easy to add other, more complicated visualizers, but in the video you simply see a representation of the ground and a wall at some distance away from the initial ball launch point.

Now let’s do some simulations showing the variation in ball travel over the course of the baseball season. These simulations were run at the average high temperature (taken on the 15^{th} of the month) and average relative humidity for the season in Detroit and Denver. The plot below shows both the average temperatures and the ball travel using the same initial launch velocity and angle as before. Since the temperature curves are relatively symmetric centered around the hottest month in July, the ball travel is relatively symmetric as well. I was surprised to see how close the spring and early summer average temperatures are in Detroit and Denver though Denver becomes hotter in the middle of the summer and continues so throughout the end of the season in October (assuming post-season baseball).

And, yes, it does all come down to air density in this simple model. So if you take the runs and plot ball travel against density, you will see the linear effect since drag is proportional to density.

Interested in this sort of modeling? Want to see some additional results? Contact us via the comments if you have any questions or feedback or would even like access to this simple model.

**John Batteh** is Group Manager and Technical Specialist at Modelon Inc. He holds a PhD in Mechanical Engineering from University of Michigan and has 15 years experience in physical modeling and simulation, with expertise in powertrain and thermofluid systems. In his current position, he is focused on helping customers leverage the power of Modelica and FMI for model-based systems engineering.