File Exchange Pick of the Week

Our best user submissions

Bouncing Ball Animation – Using Events with ODE

Jiro's pick this week is "Bouncing Ball: Tutorial for ode45 events" by Matthew Kelly.

Using animation is a great way to convey information. By animating something physical, it has an added effect of tying concepts with experience or intuition. This tutorial by Matthew is about using events with ordinary differential equation solver ode45, or any other ODE solver for that matter. He uses a bouncing ball example to show the effect of events, represented as the act of the ball coming into contact with the ground. Since a ball typically bounces over and over again, he repeatedly calls ode45 with each calculation separated by an event (contact). The simulation takes into account the energy loss when the ball bounces, defined by the coefficient of restitution. Add to that a nice terrain defined by a few sinusoids, then you get a nice animation of the ball bouncing all over the place.

Matthew has documented the code very well, so it's easy to pick up and understand. He's modularized the code so that you can customize it to your needs. For example, he has a single function Set_Parameters that, well... sets your parameters. The function groundHeight defines the terrain, and the function Animate creates the animation.

I added a bit of interactivity to the terrain creation, and here are some interesting terrains I tested.

If you found this entry interesting, Matthew has contributed quite a bit to the File Exchange. Be sure to check it out.


Let us know what you think here or leave a comment for Matthew.

Published with MATLAB® R2015b



To leave a comment, please click here to sign in to your MathWorks Account or create a new one.