title: How is my Rigid Body Collision code inconsistent?
body: <p>I've been trying to replicate the system found here: <a href="http://www.myphysicslab.com/collision.html" rel="nofollow">http://www.myphysicslab.com/collision.html</a></p>
  
  <p>So far this is my code (for the case of hitting an infinitely massive object, like an immovable wall):</p>
  
  <pre><code>public static Orientation collide( float bodyMass_1, float bodyVelocityX_1, float bodyVelocityY_1, float bodyAngleMomentum_1 , float pointXFromCenterX_1, 
  float pointYFromCenterY_1, float momentOfInertia_1,
  float edgeNormalX, float edgeNormalY, float elasticity )
  {
      Orientation returning;
  
      float outAngleMomentum_1;
  
      float outVelocityX_1, outVelocityY_1;
  
      float relativeNormal;
      float deltaParameter;
  
      float pointVelocityX_1, pointVelocityY_1;
  
      pointVelocityX_1 = bodyVelocityX_1 - bodyAngleMomentum_1 * pointYFromCenterY_1;
      pointVelocityY_1 = bodyVelocityY_1 + bodyAngleMomentum_1 * pointXFromCenterX_1;
  
  
      System.out.println( edgeNormalX );
      System.out.println( edgeNormalY );
  
      relativeNormal = (float) Funct3D.dotProduct( pointVelocityX_1, pointVelocityY_1,edgeNormalX, edgeNormalY );
  
  
      if ( relativeNormal &lt; 0 )
      {
  
          deltaParameter = (-(1 + elasticity) *( (float) Funct3D.dotProduct( pointVelocityX_1, pointVelocityY_1, edgeNormalX, edgeNormalY ) ))/ 
          ( 1/bodyMass_1 + Funct3D.sqr( (float) Funct3D.perpDotProduct(pointXFromCenterX_1,pointYFromCenterY_1,edgeNormalX,edgeNormalY)) / momentOfInertia_1 );
  
          outVelocityX_1 = bodyVelocityX_1 + deltaParameter * edgeNormalX / bodyMass_1;
          outVelocityY_1 = bodyVelocityY_1 + deltaParameter * edgeNormalY / bodyMass_1;
  
          outAngleMomentum_1 = bodyAngleMomentum_1 + (float)     Funct3D.perpDotProduct(pointXFromCenterX_1, pointYFromCenterY_1,     deltaParameter*edgeNormalX, deltaParameter*edgeNormalY ) / momentOfInertia_1;
  
          returning = new Orientation( outVelocityX_1, outVelocityY_1, outAngleMomentum_1 );
      }
      else
      {
          System.out.println( "NO COLLISION" );
          returning = new Orientation( bodyVelocityX_1, bodyVelocityY_1, bodyAngleMomentum_1 );
      }
      return returning;
  }
  </code></pre>
  
  <p>The results of my code often result in the velocity not reflecting through the normal, or just an entire lack of conservation of momentum. Even when I have it just have it output the results immediately after execution, the results show that it isn't a matter of registering the collision several times, it occurs on its first run as well.</p>
  
  <p><code>dotProduct</code> returns the dot product of two vectors.</p>
  
  <p><code>perpDotProduct</code> returns the perp dot product of two vectors</p>
  
  <p>If you need anything explained, or if you'd like to request the code scope to be widened any, please feel free to ask. </p>