Complete 2D Bouncing Ball (with Wind!) Using Simulink (30 Minutes)

by william_ckm in Design > Software

121 Views, 1 Favorites, 0 Comments

Complete 2D Bouncing Ball (with Wind!) Using Simulink (30 Minutes)

Ever tried tossing a ping pong ball into a cup from across the room, only to watch it miss by a frustrating inch every single time? Landing that perfect arc feels like pure luck—until you let physics and math do the heavy lifting.

The classic Simulink "bouncing ball" model is a staple beginner project, but standard 1D tutorials only track vertical height over time. In this quick, 30-minute bite-sized project, we are taking things to the next level by introducing 2D motion! By adding horizontal displacement (X-axis) alongside vertical gravity and bounce mechanics (Y-axis), we transform a basic simulation into a quantitative tool capable of predicting actual trajectories.

To spice things up, we will also model environmental conditions by adding a wind variable. Using a standard Integrator block to apply constant horizontal acceleration, you can simulate headwinds that stall your shot or tailwinds that push it further. Whether you are looking to master basic Simulink block routing or just want to engineer the ultimate beer pong strategy, this fast-paced upgrade is the perfect weekend project. Grab your laptop, fire up MATLAB, and happy simulating!

Supplies

You'll need access to Mathworks' Simulink software. No concerns - don't even fuss about the 30-day free trial. Mathworks provides 20 hours of MATLAB per month for FREE through this link: https://ww2.mathworks.cn/en/products/matlab-online/matlab-online-versions.html.


Apart from that, no physical objects!

Open Up the Software

Once you open up MATLAB online, you should be presented with a screen similar to the first image above. Then, click New (top left corner) -> Simulink Model (bottom). A model will open up, just like in the second image.

Use Mathworks' 1D Bouncing Ball Model As a Base Model

To simplify the process, Mathworks has kindly provided the 1D Bouncing Ball Model for the public here: https://ww2.mathworks.cn/help/simulink/slref/simulation-of-a-bouncing-ball.html. After opening in Simulink online, you should be presented with the above model.

Upgrade to 2 Dimensions

But where's the new, cool part? That will have to be added manually. Since Mathworks has already taken care of the vertical position and velocity components, we only need to add the horizontal component. Add a constant block by first clicking any white space in the middle and typing 'constant' straight-up. Set the constant to be the horizontal velocity component (which is constant). Add an integrator block. Double-click the block and make sure the initial condition is 0. Then click and connect the arrows to connect the constant block to the integrator.

Add an 'XY Graph' block. Connect the output from the new integrator block to the top input, and the 'position' output from Mathworks' model to the bottom input.

Simulate!

Finally, click the 'Run' button on the top. After it loads, double click the XY graph block to open up the plot. Voila! Here's the trajectory of your bouncing ball. But wait - it looks the same as the Mathworks 1D graph, except that the X-axis is horizontal displacement, not time!

But we can spice things up - wind! In our model, wind will blow in the horizontal direction, leading to a constant acceleration or deceleration.

Add the Wind Factor

To add wind, change your constant block from 'horizontal velocity component' to 'wind'. The block is now an acceleration block, not a velocity block. Make sure it is positive if you want the wind to blow in favour of the ball's motion, and negative if it blows against the ball. Add another integrator, and connect your wind block to this new integrator first, before connecting to the right-most integrator (your original one). Double click your new integrator, and set the initial condition to your desired initial horizontal velocity (i.e. what you had BEFORE in the constant block). For me, it was 15.

Afterwards, hit run again and see the new graph. You can change the parameters (wind, coefficient of restitution i.e. how much velocity the ball loses with each bounce, initial horizontal and vertical velocities) however you want. Enjoy!