I am the one who wrote the source code for the return ball that you referenced. If you download and try this code, you will see that it works fine.
The following code is correct (the way you originally used it):
// collision impulse float i = (-(1.0f + RESTITUTION_CONSTANT) * vn) / (im1 + im2); CGPoint impulse = ccpMult(mtd, i);
This is a very common physical code, and you can see it in almost exactly the same way in the following examples:
This is correct, and it is ~ not ~ creating CoR over 1.0, like others. It calculates the relative momentum vector based on mass and Restitution Factor.
Ignoring friction, a simple example of 1d is as follows:
J = -Vr(1+e) / {1/m1 + 1/m2}
Where e is your CoR, Vr is your normalized velocity, J is the scalar value of the pulse velocity.
If you plan to do something more advanced, I suggest you use one of the many existing physics libraries. When I used the code above, it was good for a few balls, but when I increased it to several hundred, he began to choke. I used the Box2D physics engine, and its solver could handle more balls, and that is much more accurate.
In any case, I looked at your code and at first glance it looked beautiful (this is a fairly correct translation). This is probably a small and subtle error with the wrong value passed in or the mathematical problem of the vector.
I donβt know anything about iPhone development, but I would suggest setting a breakpoint at the top of this method and follow every step resulting from it and find where the bloat happens. Make sure the MTD is correctly calculated, impact speeds, etc. Etc., until you see where a large increase is introduced.
Send back the values ββof each step in this method, and we will see what we have.