/* Computes the momentum exchange for an elastic collision. One of the objects is at (0, 0) with velocity (0, 0). */ float []elasticCollision(float x, float y, float momx, float momy, float kick) { float []ret = new float[2]; float d = dist(0, 0, x, y); final float momInward = - (momx * x + momy * y) / d; if (momInward <= 0) return ret; ret[0] = (kick + momInward) * x / d; ret[1] = (kick + momInward) * y / d; return ret; }