Minority Opinions

Not everyone can be mainstream, after all.

Bouncing Math

leave a comment »

It should normally be impossible for three-dimensional balls of different sizes to be forced into a two-dimensional plane together. Nevertheless, I’ve discovered a situation where I want to calculate their trajectories when they bounce off each other.

Fortunately, I get to assume perfect elasticity. A bit more realism would be nice, but letting the input energy cancel out completely turns a quadratic equation linear. (The other solution is where the balls miss each other completely.) Because it’s been long enough since my mechanics course, I incidentally proved conservation of momentum along the way, but came up with the following:

factor = 2*((a.x-b.x)*((b.m**2)*b.v.x - (a.m**2)*a.v.x) + (a.y-b.y)*((b.m**2)*b.v.y - (a.m**2)*a.v.y))/((a.m**3 + b.m**3) * (a.r + b.r)**2)
a.v.x += factor * a.m * (a.x-b.x)
a.v.y += factor * a.m * (a.y-b.y)
b.v.x -= factor * b.m * (a.x-b.x)
b.v.y -= factor * b.m * (a.y-b.y)

Yes, it’s messy. Messy enough that I distrusted it at first (mass cubed, really?), despite the units working out properly, until I derived it again through a different method. It’s much simpler in the coordinates of the impact force, but gets just as complicated on translation back to cartesian coordinates.

Forgive my combination of programming syntax with physics-length variable names, for I have been delving into both worlds at once. They should all be obvious from the context, except that .r is for the radius of the ball; that bit is a shortcut for calculating the absolute distance between their centers, which itself is part of a proxy for the impact force angle. The whole thing only really applies at the precise moment of collision, assuming the balls are perfectly rigid. Fortunately, I’m defining the universe in which this happens, so I get to make the rules.

Now I have to decide whether to use this, or whether a vastly simpler calculation will produce results that look good enough.

Update: My math was wrong.  Use the new equations instead.

Written by eswald

21 Aug 2012 at 9:43 pm

Leave a comment