why do waves bend when entering a different medium