Refraction is the change in direction of light when passing from one medium to another of different density. Snell's law states that the ratio of sines of the angle of incidence and refraction is equal to the ratio of refractive indices of the two media. Due to refraction, the sun appears above the horizon before actual sunrise and remains visible after sunset. Stars twinkle because their light refracts through our atmosphere, causing their apparent position to fluctuate. Planets do not twinkle as their extended disks average out the effects of refraction. The sun's disk appears flattened at sunrise and sunset due to refraction and mirages caused by variations in the atmosphere's density.