{"id":9063,"date":"2014-02-11T09:35:46","date_gmt":"2014-02-11T14:35:46","guid":{"rendered":"http:\/\/scienceblogs.com\/principles\/?p=9063"},"modified":"2014-02-11T09:35:46","modified_gmt":"2014-02-11T14:35:46","slug":"follow-the-bouncing-ball","status":"publish","type":"post","link":"http:\/\/chadorzel.com\/principles\/2014\/02\/11\/follow-the-bouncing-ball\/","title":{"rendered":"Follow the Bouncing Ball"},"content":{"rendered":"<p>Last week, Rhett did a <a href=\"http:\/\/www.wired.com\/wiredscience\/2014\/02\/animating-bouncing-ball\/\">post on animating a bouncing ball in VPython<\/a>. This was mostly making a point about the distinction between real simulation and animation, along the lines of <a href=\"http:\/\/scienceblogs.com\/principles\/2014\/02\/10\/the-social-construction-of-gravity\/\">yesterday&#8217;s post on social construction of videogame reality<\/a>. But, of course, my immediate reaction was, &#8220;That&#8217;s not how a bouncing ball looks&#8230;&#8221; <em>This<\/em> is how a bouncing ball looks:<\/p>\n<p><iframe loading=\"lazy\" width=\"420\" height=\"315\" src=\"\/\/www.youtube.com\/embed\/kLrHWVJ555M\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>(As you can see from the watermark, I&#8217;m trying out a new video editor&#8230;)<\/p>\n<p>This is footage of four different types of balls bouncing on a lab cart in our stockroom, shot in gratuitous slow motion (240 fps) because I&#8217;m still playing around with my new camera. These are what I happened to have lying around: a black rubber &#8220;happy&#8221; ball from a lab set, a hard plastic projectile from a PASCO launcher, a ping-pong ball, and a racquetball. There are some significant differences between them&#8211; the projectile ball stops really quickly, while the ping-pong ball goes on forever&#8211; but they all have one thing in common: the bounce height decreases rapidly as the bouncing goes on.<\/p>\n<p>So, if you want to <em>really<\/em> animate a bouncing ball, you need to capture that. And, of course, being a great big nerd, I&#8217;m far more interested in simulation than animation, so let&#8217;s think about the physics, here, and how to code it up in VPython.<\/p>\n<p>First and foremost, we need to think about how to handle the bouncing behavior. But, of course, that&#8217;s pretty easy and obvious, given all the previous <a href=\"http:\/\/scienceblogs.com\/principles\/?s=vpython\">futzing around with VPython simulation<\/a> we&#8217;ve done here: we just treat the ball as a spring. I assigned a fairly arbitrary spring constant to the ball, and put in an if-then statement to apply a spring force if the center of the ball was within a radius of the &#8220;floor.&#8221; Then I fiddled with the spring constant to give reasonable behavior, namely keeping the center of the ball from getting all the way to the floor. That gives you a bouncing behavior that looks just like Rhett&#8217;s constant acceleration animation:<\/p>\n<figure id=\"attachment_9065\" aria-describedby=\"caption-attachment-9065\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/scienceblogs.com\/principles\/files\/2014\/02\/bouncing_no_drag.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/scienceblogs.com\/principles\/files\/2014\/02\/bouncing_no_drag.png\" alt=\"Bouncing ball screenshot with no dissipation.\" width=\"550\" height=\"345\" class=\"size-full wp-image-9065\" srcset=\"http:\/\/chadorzel.com\/principles\/wp-content\/uploads\/2014\/02\/bouncing_no_drag.png 550w, http:\/\/chadorzel.com\/principles\/wp-content\/uploads\/2014\/02\/bouncing_no_drag-300x188.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-9065\" class=\"wp-caption-text\">Bouncing ball screenshot with no dissipation.<\/figcaption><\/figure>\n<p>So, you know, physics works. <\/p>\n<p>Of course, the more interesting question is how to handle the decay of the bounce. To put that in, we need to think about the physics of <em>why<\/em> it decays. This is easiest to understand in terms of energy: the falling ball has some kinetic energy, and when  it hits the table, some of that energy is converted into thermal energy, heating up the ball and the table by a tiny amount. That thermal energy can&#8217;t be recovered and turned back into energy of motion, so when the ball heads back up, it has less kinetic energy than when it started. That means that when it reaches the peak of its flight, turning all of the kinetic energy into gravitational potential energy, it&#8217;s not as high as it was on the previous bounce.<\/p>\n<p>So, how to model this? Well, the cheap and easy thing to do would be to just insert a line that automatically decreases the energy when it bounces. But we didn&#8217;t explicitly calculate the energy of the ball at any point in the simulation above, just the forces that act on in. Besides, we&#8217;re trying to do physics here.<\/p>\n<p>So, how do you lose energy? Well, introductory Newtonian mechanics tells us that energy is converted to thermal energy through the action of &#8220;non-conservative&#8221; forces (a term that causes no end of confusion, but we&#8217;re kind of stuck with it&#8230;), which are easiest to understand by considering their opposite.. A &#8220;conservative&#8221; force is one where the work done as you move between two points is independent of the path you take from one point to the other, and those give you potential energy&#8211; gravity is a good example. As you lift something up, gravity resists your motion, but if you lower it, gravity helps you move it. The total work done by gravity thus depends only on the difference in heights&#8211; if you lift something up above the final position, then lower it back down, gravity resists the motion for part of that, and helps for another part, and those bits cancel each other out.<\/p>\n<p>A non-conservative force, on the other hand, is one where the work done depends on the path that you follow&#8211; a short path means little work, and a longer path requires more work. Friction and air resistance are the classic examples: because friction is always in the direction opposite the direction of motion, it never helps you, and only hurts. A long path means more work against friction, which is why people moving furniture always follow the most direct route they can when sliding stuff across the floor.<\/p>\n<p>So, to lose energy, we want to add a force that is always in the direction opposite the ball&#8217;s motion. There are two classic, simple mathematical forms for this kind of thing if you&#8217;re thinking about drag forces on a particle moving in a fluid: For thick fluids, there&#8217;s a viscous drag force that depends on the velocity, and for thinner ones, there&#8217;s a drag force that depends on the <em>square<\/em> of the velocity. Since the VPython simulation tracks velocity directly, as a vector, both of these are easy to implement with an extra line in the if-then statement where I calculate the spring force. Of course, I&#8217;m not sure which of these to prefer, so I coded both of them up.<\/p>\n<p>But then, it&#8217;s not clear why either of those models would apply; they&#8217;re just convenient and familiar things to add in. The actual dissipation comes about through the motion of the atoms and molecules making up the ball and the table, which aren&#8217;t necessarily like particles in a fluid. But those are also the very things that give rise to the spring force, so maybe a more appropriate method would be to add a drag force that&#8217;s a fixed fraction of the spring force (but still always in the direction opposing the motion). That&#8217;s also pretty easy to do, so I added a third calculation to the loop.<\/p>\n<p>So, what&#8217;s the end result? Well, here are three traces showing the three different models, for a fairly arbitrary choice of parameters that give 50 bounces before the height of the bounce is less than 5% of the radius of the ball. (This is an unrealistic set of values, but it highlights the difference between the models, and we&#8217;re just playing at the moment).<\/p>\n<figure id=\"attachment_9066\" aria-describedby=\"caption-attachment-9066\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/scienceblogs.com\/principles\/files\/2014\/02\/bouncing_composite.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/scienceblogs.com\/principles\/files\/2014\/02\/bouncing_composite.png\" alt=\"Left: bouncing ball with drag linear in velocity. Middle: bouncing ball with drag quadratic in velocity. Right: bouncing ball with drag a fixed fraction of the spring force.\" width=\"550\" height=\"178\" class=\"size-full wp-image-9066\" srcset=\"http:\/\/chadorzel.com\/principles\/wp-content\/uploads\/2014\/02\/bouncing_composite.png 550w, http:\/\/chadorzel.com\/principles\/wp-content\/uploads\/2014\/02\/bouncing_composite-300x97.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-9066\" class=\"wp-caption-text\">Left: bouncing ball with drag linear in velocity. Middle: bouncing ball with drag quadratic in velocity. Right: bouncing ball with drag a fixed fraction of the spring force.<\/figcaption><\/figure>\n<p>On the left is the linear-in-velocity drag force, in the middle is the velocity-squared drag force, and on the right is the fraction-of-the-spring-force drag. You can see that there&#8217;s a big difference between the linear and quadratic models&#8211; the quadratic version dies down much faster, but looks like it sort of levels out and continues at a lower amplitude for a long time. If you can see a difference between the linear and fraction-of-drag models, you&#8217;ve got better eyes than me. In fact, they&#8217;re nearly identical. Don&#8217;t believe me? Here are some graphs:<\/p>\n<figure id=\"attachment_9067\" aria-describedby=\"caption-attachment-9067\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/scienceblogs.com\/principles\/files\/2014\/02\/bounce_time.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/scienceblogs.com\/principles\/files\/2014\/02\/bounce_time.png\" alt=\"Time of the nth bounce for the simulated ball under the different drag models.\" width=\"550\" height=\"425\" class=\"size-full wp-image-9067\" srcset=\"http:\/\/chadorzel.com\/principles\/wp-content\/uploads\/2014\/02\/bounce_time.png 550w, http:\/\/chadorzel.com\/principles\/wp-content\/uploads\/2014\/02\/bounce_time-300x232.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-9067\" class=\"wp-caption-text\">Time of the nth bounce for the simulated ball under the different drag models.<\/figcaption><\/figure>\n<figure id=\"attachment_9068\" aria-describedby=\"caption-attachment-9068\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/scienceblogs.com\/principles\/files\/2014\/02\/bounce_height.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/scienceblogs.com\/principles\/files\/2014\/02\/bounce_height.png\" alt=\"Height of the nth bounce, under three different drag models.\" width=\"550\" height=\"425\" class=\"size-full wp-image-9068\" srcset=\"http:\/\/chadorzel.com\/principles\/wp-content\/uploads\/2014\/02\/bounce_height.png 550w, http:\/\/chadorzel.com\/principles\/wp-content\/uploads\/2014\/02\/bounce_height-300x232.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-9068\" class=\"wp-caption-text\">Height of the nth bounce, under three different drag models.<\/figcaption><\/figure>\n<p>The top graph shows the time of the nth bounce&#8211; defined as the time when VPython noticed that the velocity has changed from down to up&#8211; and the bottom graph shows the height of the nth bounce&#8211; defined as the time when VPython noticed that the velocity has changed from up to down. These are closely related, of course&#8211; the time between bounces is the time to go up to a given height and come back down&#8211; but they&#8217;re two easy things to measure and graph. And the important thing to notice from these is that there&#8217;s basically no difference between the linear-drag and fraction-of-spring models. Why is that? I have no idea. If you know, please enlighten me.<\/p>\n<p>So, how do these compare to the real bouncing balls from the video at the top of this post? Well, this is where the gratuitous sow motion kind of bites me in the ass&#8211; analyzing these with Tracker takes frickin&#8217; forever because of the high frame rate. I do have numbers for one of the clips, though, but this post is kind of long already, so we&#8217;ll save that for tomorrow&#8230;<\/p>\n<p>In the meantime, if you&#8217;d like to play with the simulation yourself, play &#8220;find the stupid coding error,&#8221; or just point and laugh at my rudimentary VPython, the <a href=\"https:\/\/gist.github.com\/orzelc\/46de3a75611a3aa6b90e\">code for this is on Gist<\/a>. Have fun.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week, Rhett did a post on animating a bouncing ball in VPython. This was mostly making a point about the distinction between real simulation and animation, along the lines of yesterday&#8217;s post on social construction of videogame reality. But, of course, my immediate reaction was, &#8220;That&#8217;s not how a bouncing ball looks&#8230;&#8221; This is&hellip; <a class=\"more-link\" href=\"http:\/\/chadorzel.com\/principles\/2014\/02\/11\/follow-the-bouncing-ball\/\">Continue reading <span class=\"screen-reader-text\">Follow the Bouncing Ball<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":9064,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[451,663,7,11,677,136],"tags":[],"class_list":["post-9063","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computing","category-everyday","category-physics","category-science","category-simulations","category-video","entry"],"_links":{"self":[{"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/posts\/9063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/comments?post=9063"}],"version-history":[{"count":0,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/posts\/9063\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/media\/9064"}],"wp:attachment":[{"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/media?parent=9063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/categories?post=9063"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/chadorzel.com\/principles\/wp-json\/wp\/v2\/tags?post=9063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}