Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > b46ffe5e800f647c4d5338ad20382214 > files > 5

opticalraytracer-2.7-1.fc13.noarch.rpm

*** Help for OpticalRayTracer

OpticalRayTracer is (c) Copyright 2008, P. Lutus.

OpticalRayTracer is released under the GPL (the GNU General Public License). Additionally, it is CareWare (no money, now or ever). If you are curious, visit the CareWare Page at www.arachnoid.com/careware.

For recent revisions and further information, visit the OpticalRayTracer Home Page at http://www.arachnoid.com/OpticalRayTracer.

*** Introduction

OpticalRayTracer is a Linux-specific C++ program meant to analyze and model systems of lenses. It accurately models the physics of lenses, including the effect known as dispersion. But perhaps the most remarkable thing about OpticalRayTracer is that it updates and displays complex ray tracing paths in real time, as the user moves virtual lenses around on a virtual optical bench. This allows the user to very quickly learn the behavior of a system of lenses, compare, experiment, and just play.

OpticalRayTracer places its configuration file in a directory it creates, so your settings and choices are preserved. This directory is located at [PROGDIR] on your machine, and it contains a configuration file named "OpticalRayTracer.ini" containing quite a lot of detailed information unique to your use of the program.

I mention this because (a) if you want to analyze or process the results of your work with OpticalRayTracer, the file [PROGDIR]/OpticalRayTracer.ini contains a lot of numeric information in plain-text form, and (b) if you have gotten into difficulty and just want to start over, simply delete this file and run OpticalRayTracer again.

This file contains a very detailed snapshot of your last session with OpticalRayTracer, with lens specifications and positions, suitable for exporting into other environments. To create this file and its picture of your optical setup, simply exit OpticalRaytracer, navigate to [PROGDIR] and read the file.

*** First Steps

Since you are reading this, you have successfully installed OpticalRayTracer on your Linux system, and are ready to try some experiments. If you want to follow these help instructions closely while using the program, you may want to consider making a copy of this help file. To do this, simply click the help display, then press Ctrl+A (select all), then Ctrl+C (Copy). Then paste the text into your favorite text editor/word processor for reading in a separate window, or printing.

When it is first run, the program will automatically create two common lenses for you, a double-convex lens and a double-concave lens. Click the "Ray Trace Display" tab and you will most likely see these two default lenses. If you do not see any lenses, click the "Configuration" tab, click the "Create Default Lenses" button, then return to the ray trace display.

Navigation within the ray trace display is as intuitive as I could make it:

* To zoom in and out, use your mouse wheel.

* To pan around the display, just click the display and drag using the mouse.

* To move a lens from one place to another in the display, simply click the lens and drag it.

Notice that panning the display itself requires you to click outside any lenses, then drag. To move a lens, click directly on the lens you want to move and drag it.

Hint 1: The display has two dimensions, "x" and "y". "x" is the horizontal dimension, and positive values for x move to the right. "y" is the vertical dimension, and positive values for y move up.

Hint 2: To move large distances, first zoom out, then pan, then zoom in again. This saves time compared to clicking and dragging multiple times.

Hint 3: To determine the position of something in the display, for example the location fo a focal point, simply point the mouse cursor at the point of interest and read the mouse x and y positon in the control panel below the display.

The default setup shows six light beams passing from right to left, through the lenses. The mathematical methods used in this program are efficient enough that (with a moderately fast computer) you can move the lenses around and see how this changes the beam paths -- in real time. Try it -- move the lenses around (click on a lens and drag it) and observe the changing beam paths.

Notice that, when you click a lens, its background color changes and the "Lens Control" panel below the display is enabled. This panel allows you to change the characteristics of your lenses -- focal length, size, curvature, and many other things. Feel free to experiment with this panel's settings, see how they change the appearance of the lenses and the beams.

To change the settings for a lens, first click the lens, then use the lens control panel to make the changes you want.

It will help to know a little about optics to understand what you are seeing. If you already know the basics, you can safely skip the next few lines.

** The Basics of Lenses

Very basically, a lens is a simple way to bend light beams. Imagine a row of soldiers marching, side by side. To change the direction they are marching, it is necessary to make some of the soldiers slow down temporarily. Now let this picture of marching soldiers help you imagine a light wave, traveling through space. Just as with the soldiers, to make the wave change direction, you have to think of a way to make part of the wave slow down. That is what a lens does -- it selectively slows parts of a light wave.

A convex lens is thicker in the middle than at the edges, and, as it turns out, light takes longer to pass through glass than through air. What this means is that the light that passes through the middle, thickest part of the lens, is slowed down compared to the light that passes through the thinner parts near the edges of the lens. This has the effect of shaping the wavefront that emerges from the lens -- the middle of the emerging wavefront is delayed, and the wave's overall shape is concave, with a depression in the middle. The wavefront has been shaped to converge on a point some distance away from the lens, and that is exactly what it does.

Such a lens could be used to focus parts of a real-world scene onto a piece of film or an image sensor. The ability of a lens to focus accurately is a central issue in lens design and, as it turns out, the most common kind of lens, with a spherical shape, is actually quite a bad lens. Its only advantage is that it is easy to make -- everything after that is downhill.

** Types of Lenses Supported in OpticalRaytracer

OpticalRayTracer will happily let you play with various kinds of simple, spherical lenses in its virtual playground, but it also includes some mathematical methods that allow you to fashion some rather extraordinarily good lenses called "hyperboloids," famous for their accuracy ... and their difficulty of manufacture. These kinds of lenses are so expensive that it is simpler -- and much less expensive -- to build and test such lenses using OpticalRayTracer than to try to purchase real-world examples. This is an answer to the oft-heard objection to too much gazing at glowing computer screens. We are excused, just this once, by pointing out that building an exotic lens on a computer screen, changing its characteristics, experimenting, would cost thousands of dollars if rendered in glass instead of computer code, and would require months of fabrication time as well.

** Easy Tutorial

I want you to perform your own experiments, but here's a simple tutorial to get you started. Using the default lenses automatically created when you run OpticalRayTracer the first time, temporarily drag the concave lens (the lens at the right) out of the optical path. If you drag it a small distance, it will jump back into place, realigning itself with the beam line (ordinarily this automatic feature is a good thing). So drag it a good distance up or down, temporarily removing it from the beam path. Now notice the double-convex lens at the left. If you click this lens and then read its characteristics in the control panel below it, you will discover that it has a "lens radius" of 2 units and a "sphere radius" of 6 units. What do these terms mean?

* "Lens Radius" refers to the distance from the center to the edge of the lens itself. Very simple.

* "Sphere radius" refers to imaginary spheres that our lens is composed of. Imagine two spheres of glass floating in space, overlapping to some extent, and then imagine that our lens represents the parts of the spheres that overlap. To help in visualizing this, draw two circles on a piece of paper using a coin and a pencil, and be sure to allow some overlap between the circles. The area where the circles overlap is our lens. Starting with this paper diagram, one need only use imagination to expand the picture to three dimensions and glass.

As it turns out, the mathematics behind lenses relies very much on this idea of overlapping spheres, hyperboloids, and some other useful shapes. So if you can mentally picture two overlapping spheres, you will be able to predict what will result from your typing particular numbers into OpticalRayTracer. For example, to create a lens with one side convex and one side flat, you might choose to enter a very, very large radius for one side. Like this:

1. Select the double-convex lens by clicking it.

2. Deselect the "symmetrical" check box, which will allow you to choose different traits for the left and right-hand sides of your lens.

3. Enter "1000" into the "Left Sphere Radius" window and press Enter.

4. You will see that the right-hand side of the lens has become flat, and (because we now have a lens with less overall curvature), the beams travel farther to the right before converging. The lens is said to have a longer focal length.

At this point, you may wonder why an entry defining the left-hand sphere had its effect on the right hand side of our lens. The answer is that the imaginary spheres are overlapping, and the right-hand part of our lens is defined by an imaginary sphere centered to the left of the lens. I mention this now to avoid confusion later on. Refer again to the paper drawing of circles suggested above, noticing that the circle that defines the right-hand side of the overlapped region (e.g the lens) is centered to the left of the overlap area.

Now for something a tiny bit more advanced.

1. Select the convex lens by clicking on it.

2. Re-enter "6" for "Left Sphere Radius," press Enter, then enable "symmetrical" again by clicking its checkbox, restoring our lens to its original state -- a simple, symmetrical double-convex lens.

3. Drag the mouse on the display to pan over to the region between x = 5 and 6 (remember that "x" means the horizontal axis), where the beams should now be converging. Once you have centered this part of the display, use the mouse wheel to zoom in a bit for a closer look.

4. While looking as the point where the beams converge, click the "Left Hyperboloid" checkbox (because you selected "symmetrical" above, this entry will affect both sides of our lens). The lens focus should improve.

A quick reality check -- what constitutes an "improvement" in a lens? Well, ideally, all the beams should converge on a single point, rather than taking slightly different paths as they are doing now.

5. Now we are going to fine-tune our lens by entering a value for hyperboloid curvature. Type ".074" into the "Left Curv. Fact." window, and press Enter. If you have entered all the right values up to now, this should produce a nearly perfect focus -- all the beams should converge on a single point, located at about x = 4.996.

To discover how accurate this focus is, simply center the focal point in the display and zoom in on it. Eventually you will get to a point where you can see some small imperfections in the focus. This will become visible about the time OpticalRayTracer can no longer support the level of magnification in use (which happens at a zoom factor of about 15). In any case, this class of lens design is very advanced and (no surprise) very difficult to manufacture.

*** Intermediate Steps

It cannot hurt for you to know something more about lenses than has already been presented, and I will assume this is true as we move along.

** The Lens Controls Panel

Please play with some of the settings in the "Lens Controls" panel to see what effect they have. Notice that you can reposition a lens exactly by entering its x and y coordinates -- this is a way to get around the fact that it is difficult to position a lens precisely using the mouse.

Notice the window marked "IOR". This means "Index of Refraction," a value representing the ratio of the speed of light through the lens in question to a vacuum (with an IOR of 1.0). If you set this value to 1.0, the lens will no longer deflect the light beams, because in essence it has been defined as empty space.

Different glasses have different indices of refraction, a property that is taken advantage of in advanced lens designs. Here's an example design that exploits this fact, and introduces the topic of dispersion.

"Dispersion" is a property of glass in which light beams of different wavelengths travel at different speeds. For example, a blue beam takes longer to move through a lens than a red beam. This causes the two colors (wavelengths) of light to focus at two different places, a trait regarded as a bad thing, called "chromatic aberration."

** Dispersion Experiment

To set up for this experiment, create a lens with these settings (you may want to simply apply these settings to one of the default created lenses):

Symmetrical: selected.
Lens Radius: 2.0
Left Sphere Radius: 4
IOR 1.52
Dispersion: 59
X position: 0.0
Y position: 0.0

Now switch to the "Configuration" panel and enter 2 for "Number of Tracing Beams". Now return to the ray trace display to see the effect.

If all your settings are correct, and if the lens has really been positioned at x = 0, y = 0, the two beams should converge at x = 2.608.

Now we'll add a dispersion calculation. Go to the "Configuration" panel and enter 8 for "Number of Dispersion beams." When you return to the ray trace display, you should see an array of colored beams near the lens focal point. In this mode, OpticalRayTracer creates colored beams, each of which has an associated wavelength. During the calculation of the ray paths, the lens dispersion property is taken into account and, just as in the real world, the lens cannot focus all these wavelengths onto a single point.

Moving right along, create a second lens (using the existing second default lens or by pressing the "New" button in the ray trace display) with these properties:

Symmetrical: deselected.
Lens Radius: 2.0
Left Sphere Radius: 1000
Right Sphere radius: -4
IOR 1.72
Dispersion: 29
X position: 0.381
Y position: 0.0

To get the required accuracy, you will need to position this lens using the control panel's "x" entry window, rather than sliding the lens about using the mouse. If all the settings on both lenses are correct and all the other required settings have been made correctly, you will see all the colored beams converge at x = 11.510, with no evident color spreading.

This, by the way, is a classic solution to the problem of chromatic aberration, using varieties of glass called "crown" and "flint," with differing properties that are exploited to make the light beams converge.

By changing the spacing between the lenses, you will quickly see that this setting is very critical to the outcome, which is why in the real world, such pairs of lenses are often glued together, or placed in a lens cell with a spacer of some durable material to maintain a particular separation.

** Lens Selection with the Mouse

In playing with this lens setup, you may notice it is difficult to select a particular lens, because the lenses are very close together and their colored border-boxes overlap quite a lot. In a case like this, just click again -- the program will cycle through the lenses that could be selected by the location of your click.

*** Advanced and Procedural Steps

Remember that the total number of beams traced is equal to the number of tracing beams (selected in the "Configuration" panel) multiplied by the number of dispersion beams, e. g. there is a dispersion beam for each chosen wavelength, times each tracing beam. So if the display slows down, this could easily be the reason -- too many beams selected. To prevent calculation of dispersion, simply set "Number of Dispersion Beams" to zero.

OpticalRayTracer uses several mathematical methods to produce its results (and you got a copy of all the source files when you downloaded the program, so you can examine the methods in detail).

** Algorithm Description

The program first calculates the location of any intersections between tracing beams and spheres or hyperboloids (our lenses). The collision detection mathematics is rather involved and won't be described in any detail here.

Having acquired a list of all possible points of collision for a particular beam, OpticalRayTracer sorts the list of results along the x dimension, then determines which intersection is next (to the right) along the beam's path.

At this point OpticalRayTracer has determined a point of collision between a tracing ray and a lens. The ray and the lens collision point each have a characteristic angle, which is used in the next computation.

** Snell's Law

"Snell's Law" is a classic optical relationship that, given arguments for incidence angle between two media and indices of refraction for the two media, determines the deflection angle. Expressed in classic form, Snell's Law is:

n1 sin(a1) = n2 sin(a2)

Where:

n1 = index of refraction of medium 1
a1 = angle within medium 1

n2 = index of refraction of medium 2
a2 = angle within medium 2

The astute reader will notice that, in passing from a medium like air with an IOR near 1.0, to a lens with an IOR of 1.5 for example, the angle must decrease. And conversely, a beam emerging from glass to air will show an increase in its angle of deflection. Also, it can be seen that an incident angle of zero will not be deflected -- it will remain zero.

In computing refraction, OpticalRayTracer uses this restatement of the Snell's Law equation:

a2 = arcsin(n1 sin(a1) / n2)

Here is a practical example:

Medium 1: air

n1 = 1.0
a1 = 20 degrees

Medium 2: crown spectacle glass

n2 = 1.52
a2 = arcsin(1.0 sin(a1) / 1.52) = 13.00365 degrees

** Dispersion Computation

The computation for dispersion follows along similar lines, but with an empirical equation less grounded in physically simple principles (and original with the author). The dispersion equation changes the index of refraction based on the wavelength of the light beam:

ior2 = ior + ((dp - w) * 500000.0) / (abbe * dp * w^2)

Where:

ior = original index of refraction for the medium.

dp = dispersion pivot wavelength, set to 589.3 nm, the sodium yellow line.

w = wavelength of the tracing beam in nm (nanometers).

abbe = Abbe's Number, a value associated with many glasses and that describes its dispersion property. Lower Abbe's numbers result in higher dispersion.

Abbe's Number is arrived at in this way:

abbe = (nd-1)/(nf-nc)

Where:

nf = a medium's index of refraction at the 486.1 nm hydrogen blue line.
nd = a medium's index of refraction at the 589.3 nm sodium yellow line.
nc = a medium's index of refraction at the 656.3 nm hydrogen red line.

The Abbe numbers for various media are arrived at in laboratory experiments. My equation simply reverses the relationship between the number and its effects, and within an accuracy of about 1%.

** Global Configuration Details

Hint 1: To change a color in the "Configuration" panel's selection list, simply click the colored button for the value you want to change. A color selection dialog will appear.

Hint 2: All the values in this list, along with a full description of the lenses you create, is preserved between sessions in a file located at [PROGDIR]/OpticalRayTracer.ini on this system.

Here is an explanation of the controls in the Configuration panel:

* Y Baseline Color. This is the color of the reference line at y = 0 in the ray trace display. If you do not want this line to appear, set its color to the color of the display background (see "Display Background" below).

* Grid Color. This is the auto-scaling grid in the ray trace display. Again, you can turn this off by setting its color to that of the background.

* Display Background Color. This color defaults to white, but in some cases, like trying to make out the colored dispersion beams, another color might be better.

* Default Beam Color. This is the beam color that is used when dispersion is not being computed. Remember that dispersion beams have an internally computed color, appropriate to their wavelength.

* Beam Intersection Color. This is the color of the dots that mark the intersections between light beams and lens surfaces.

* Intersection Dot Radius. This numeric entry specifies the size of the dots described above.

* Lens Default Box Color. This color appears surrounding unselected lenses, to aid the user in selecting a lens, and to distinguish a lens selection area from the background. If you prefer no box to appear, as above just set this color to that of the display background.

* Lens Selected Box Color. This color might be better allowed to remain in view, since it tells you which lens has been selected and to which lens the control panel settings apply.

* Lens Outline Color. This color is used to draw the profile of each lens.

* Y Snap-to-Baseline Threshold. This numeric entry sets the threshold for the behavior that returns a lens to the Y baseline when the mouse is released. This is ordinarily a good thing, a feature, but if you prefer this not to happen, set this number to zero. In truth, the feature is always active regardless of the this setting, but if you enter zero, the feature is only active at a threshold value of zero, which ... well, I think you get the idea.

* Tracing Beam Width. This setting is a bit confusing. A setting of zero causes 1-pixel-width lines to be drawn quickly. A setting of 1 or above causes a a more elaborate line-drawing algorithm to be used, one that isn't necessarily better than the default. The primary use of this settings is to create thick lines for special display purposes.

* Number of Tracing Beams. This is a setting with an large impact on program performance. OpticalRayTarcer's algorithms are swift, but choosing a large number of tracing beams can easily disable one of its best features: real-time response to user inputs. Also, it is easy to become overloaded with information as the number of beams increases. It is difficult to take advantage of the information presented by more than about 8 tracing beams. Lots of beams can be entertaining, though.

* Interactions Per beam. This determines the limit to interactions for a given beam, to avoid the computation of pointless internal reflections within a lens, for example. The default value is quite large, but a sufficiently complex lens system might require that it be increased.

* Y Start Beam position and
* Y End   Beam Position. These values determine the vertical limits for the array of tracing beams. These two numbers are typically set to fall within the chosen radius of your lenses. The default settings of -1.8 and 1.8 means all the beams fall comfortably within the default lens radius of 2 units (remember that a lens diameter is twice its radius).

* X Source Reference Plane. This is the location in the x dimension from which the tracing beams emanate. In the ray trace display, zoom out to see the location of the beam origin, then change this number to see what happens.

* X Target Reference Plane. This is the plane in the x dimension through which the tracing beams pass, regardless of their angle (desribed below). It is set by default to x = 0, so that a lens positioned here will receive the beams regardless of the other option settings.

* Beam Offset Angle. This setting is used to tilt the array of tracing beams, a way to test the off-axis performance of a lens without having to rotate the lens itself. By controlling the source angle you can observe the resulting path through a series of lenses, thus determining the off-axis performance for the entire system.

* Diverging Beam Source. This checkbox causes the tracing beams to originate in and diverge from a point source located in the X source reference plane, rather than being generated all in parallel.

* Number of Dispersion Beams. This setting produces a set of dispersion beams, with appropriate colors and wavelengths, for each tracing beam. These dispersion beams will be deflected by different amounts depending on specific lens settings, in particular the dispersion value.

Remember that the total number of ray trace computations is equal to the number of tracing beams multiplied by the number of dispersion beams, such that choosing 8 tracing beams and 8 dispersion beams results in 64 traces, fine for a fast computer, but not so great for a slower machine. To prevent the generation of dispersion beams and their associated computation overhead, simply set this value to zero.

*** Conclusion

The OpticalRayTracer Home Page is located at http://www.arachnoid.com/OpticalRayTracer, where additional documentation and other resources will be created as time passes. Be sure to visit to make sure you have the latest version of OpticalRayTracer.

There is a great deal of excellent, detailed information about optics on the Web, both theoretical and practical. Google for "optics," "ray tracing" and related topics.

*** User support

Because OpticalRayTracer is free/GPL (but please visit http://www.arachnoid.com/careware anyway), there is no user support. This help file plus the sort of knowledge available in optical textbooks and online should be sufficient to help the user make it productive.

If you detect a bug in OpticalRayTracer, please report it at http://www.arachnoid.com/messages. Make sure what you are reporting is in fact a bug. :)

-- P. Lutus, Port Hadlock, WA