collision detection algorithm python