How is the behavior of waves affected by a medium?