Optical density is a measure of the refracting power of a medium. In other words, the higher the optical density, the more the light will be refracted or slowed down as it moves through the medium. Optical density is related to refractive index in that materials with a high refractive index will also have a high optical density. Light will travel slower through a medium with a high refractive index and high optical density and faster through a medium which has a low refractive index and a low optical density. So to restate the question, why do optical media have different refractive indices?
[Physics] Why does optical media have different refractive indices
optical-materialsopticsrefraction
Related Solutions
Light is refracted on the way in and on the way out. The refractive index varies with the wavelength of the light, red being refracted less than blue.
If the "in" and "out" faces of the prism were parallel then the difference in refraction effectively cancels out - look through a window and light directions are not changed. But in a triangular prism the "cancelling " doesn't happen. You can see this if you draw a ray diagram, consult an elementary level book on optics, or just look at the above diagram.
Imagine the speed of light to be $1$ meter per second and the speed of light in the medium with a high refractive index to be $\frac{1}{2}$ meters per second.
If you have a single peak of a wave in the slower medium, that peak must move forwards at speed $\frac{1}{2}$, no matter what angle it's facing. In the faster medium, that peak must move forwards at speed $1$, no matter what angle it's facing.
The critical angle comes into play when you consider where the peak of the wave is on the boundary between two mediums. If $\theta$ is the angle between the wave direction and the surface normal and $v$ is the speed of the wave, this point travels at a speed $\csc(\theta) v$. This makes sense: if $\theta=\pi/2$, the point at the boundary is just the wave speed. If $\theta=0$, the wave passes instantly and so the question isn't really defined (because there is no point where the peak of the wave is on the boundary).
We demand $\csc(\theta_1) v_1=\csc(\theta_2) v_2$. That is, there should be a single point on the boundary where the peaks of both waves meet. The velocity of the point can be expressed in two ways, and both must be equal.
Unfortunately for the faster medium, if you have a full wave, the point on the boundary can never move slower than $v_2$, in this case, $1$ meter per second. But we're trying to send in a wave whose boundary point can move as slow as $\frac{1}{2}$ meter per second. There is absolutely no way any wave in the faster medium can satisfy that.
The result of this is an evanescent wave, where something is "transmitted" but decays exponentially (so that nothing is truly transmitted over long distances). You can't see that very well in optical light, but you can in microwaves. Take for example this Sixtysymbols video. Around three minutes in, two microwave prisms get pushed together. The reading starts to increase slowly before the two prisms are mushed up right next to each other because there is an evanescent wave "escaping" the prism but transmitting nothing over long distance. If the evanescent wave hits another prism, there is some actual transmission.
Best Answer
Refractive index describes the speed of propagation of light in a medium. So to restate your question:
The wave equation tells us that speed of propagation depends on two factors: one is an inertial term, while the other is an elastic term. Let's look at a simple case of a string. The velocity of wave propagation in a string goes as
$$v = \sqrt\frac{T}{\mu}$$ where $T$ is the tension, and $\mu$ is the mass per unit length.
When light propagates in a dielectric medium, the electrons in that medium are moved by the EM field of the light. These moving electrons in turn emit an electromagnetic wave, but this wave will be lagging in phase with the signal that caused their motion.
Because of this phase lag, the combined signal that propagates is the sum of the initial signal (now a bit smaller because it gave some of its energy to the electron) plus the phase-shifted signal from the electron. Together, they create a phase shift in the original signal - it is as though it is going slower.
The shift due to one electron is tiny; but the more electrons you have per unit volume, the greater the effect will be. The actual force with which the electrons are bound (the "elastic constant" if you like) also comes into play, so you can't simply say that refractive index scales with density - but for similar materials, it does; the following graph (from http://upload.wikimedia.org/wikipedia/en/3/3b/Density-nd.GIF) shows that similar materials with different densities have a pretty believable relationship between density and refractive index:
The wikipedia page on refractive index contains some more information on the topic...