Collision detection

Added collision detection to the magnet simulator.