title: 2D Elastic Collision Doesn't Conserve Momentum
body: <p>I have a small physics program that has a large number of balls of equal size and mass that bounce around in 2D space.  The problem I am having is that after most collisions, the momentum is increased, though sometimes it decreases.</p>
  
  <pre><code>public static void Collide(Ball b1, Ball b2)
  {
    Vector2 dist = b2.Position - b1.Position;
    float distance = dist.Length();
    Vector2 normal = dist * (1 / distance); //get collision normal
    float dotprod = Vector2.Dot(normal, b1.Velocity - b2.Velocity);
    Vector2 impulse = normal * dotprod; //compute the impulse in the direction of our normal
    //ball positions at collision: (.7071, 0.2929); (1,0)
    //initial velocities: (2, 0); (0, 0) : total momentum = 2
    b1.Velocity -= impulse;
    b2.Velocity += impulse;
    //new velocities: (1,1); (1, -1) : total momentum = ~2.828
  }
  </code></pre>
  
  <p>This is the collision algorithm after I simplified it a lot because all the balls are the same size and mass.  I've tried several different algorithms and they all produce the same results.  In a system with 100 balls, the total momentum of the system climbs to about 90 and levels off when I start with 1 ball with momentum 10 (elastic walls, no friction).  Based on the number of algorithms I have tried, it almost seems like this is how it's <em>supposed</em> to work, but it seems this is violating conservation of momentum?</p>
  
  <p>Some of the algorithms I've tried:
  <a href="http://www.vobarian.com/collisions/2dcollisions2.pdf" rel="nofollow noreferrer">http://www.vobarian.com/collisions/2dcollisions2.pdf</a> (from Wikipedia)
  and <a href="https://stackoverflow.com/questions/345838/ball-to-ball-collision-detection-and-handling">Ball to Ball Collision - Detection and Handling</a></p>