Collision function for N-body codes