math for collision detection (constraints)