Reputation: 33
I've been struggling with getting to the right vector values based on 2 bouncing circles/balls. I know when they bounce; using Pythagoras, but then I'm lost. I know I would probably have to use trigonometry cos/sin/tan2.
The situation, explained in my image
(source: microshift.net)
Found a couple of examples online, but even with those, I can't figure it out!
Made 2 HTML5 experiments over here.
In one of the examples the 2nd/bigger ball is static, in the other example the larger ball can be moved by moving the mouse cursor.
Can you please give an calculation example based on the known variables?
Upvotes: 3
Views: 2919
Reputation: 69182
You basically want to use conservation of momentum (always) and conservation of energy (assuming you want a perfectly elastic collision). A nice little graphic and the equations are shown here. (In the graphic, the objects are the same size, but the size doesn't matter. All that matters is the mass of the two circles or spheres and the angle of the line or plane between the two surfaces at the moment of collision -- which will just be perpendicular to the line that has the centers and contact point.)
That's the basics, then you can deal with the different variations in the following ways:
case both objects are moving at time of impact:
To deal with the case when both objects are moving, it's easiest to transform into a reference frame where one is stationary, and then back again. That is, subtract the vector velocity of object #2 from both objects #1 and #2 (giving object #2 zero velocity), do the calculation, and then add this same vector velocity to both objects. You could, of course, write down the full equation for this, but it's easier to just transform and transform back.
case for one object held fixed throughout:
If you want to hold one of the objects fixed, you just use angle of incidence equal angle of reflection, that is, find the tangent plane (3D) or line (2D) at the time of impact (this will just be the line or plane perpendicular to the line between the centers, that will also include the point of contact) and bounce the object off this plane/line. (You can see in the equations that this is basically the case where one object has infinite mass, and sometimes it's easier to just do it this way, if say, you've already written this for both objects being free to move.)
case for one object moved with mouse cursor: If one object is moved with the mouse cursor, I assume you want it to look like it has infinite mass, that is, the cursor completely pins the object exactly at the cursor's location. In this case, just combine the previous two cases, that is, transform all motions into the reference frame of the cursor's object (by subtracting its velocity from everything), do the calculation as for the object being held fixed, and then add the same velocity to transform back again. (It would also look good, imho, to have the cursor object movable but held by a damped spring to the cursor's location, but that's a separate issue.)
Upvotes: 3