TRACE - A Simple Ray Tracing Program for Axially Symmetric Optical Systems

TRACE is a simple to use ray tracing program that runs under DOS
on a single graphics panel. It is for axially symmetric optical systems only,
but can handle relatively complex problems with both lenses and mirrors.
Click here to download TRACE.ZIP


Introduction

The ray tracing program described herein was created to model various optical
configurations useful in both visual and photographic situations. It works
well for designing and analyzing axially symmetric optical systems that
amateur telescope makers either contemplate building or actually build, and
the human interface is both simple and interactive. It is a DOS based
program that should run well on computers with minimal resources by today's
standards. A 386 based machine with EGA graphics capability is all that's
required, although it should run fine on more capable systems also.

In addition to the files in TRACE.ZIP, you will also need an ASCII editor to
create and modify the design files.


Disclaimer

Although I have tested TRACE for over a year on various published designs
and have found no flaws in the analysis, TRACE has not been exhaustively
tested. So, use this program at your own risk. I make no claims about its
accuracy or suitability for analyzing your problem. Freely distribute this
program to others for their own personal use. Commercial use is strictly
prohibited. Copyright Dave Rowe, 1998.


What the Program Does, An Overview

TRACE is a general purpose ray tracing program for axially symmetric optical
systems that have reflective and refractive surfaces. In other words, it will
ray trace and present spot diagrams for optical systems that have components
without tilt or wedge. This was done on purpose to remove complexity from
the user interface. So, if you are trying to simulate the performance of
your favorite Yolo or Trischiefspiegler, you’ve come to the wrong place.
There are other programs available that will do this for you. On the other
hand, if you want to design one of the enormous variety of axially
symmetric optical systems, or just look at the images produced by a simple
Newtonian telescope, then this program may be just what you need.

The single graphics panel generated by this program displays: three spot
diagrams at three different user specified off-axis angles, a parameter
input area so that the design can be hand optimized in real time, several
useful results of the current simulation including the RMS spot size and
effective focal length of the system and a hot key menu to help you remember
how to operate the program. In addition, three different wavelengths to be
simulated can be entered, and the spot diagram field of view can be changed,
all interactively.

The program also has two optimization routines which can be used with
varying degrees of success for decreasing the spot size. The two
optimization methods that are currently available are gradient descent and
random search. Neither works wonders but a careful use of these has produced
nice results.


The Zipped Files

The zipped files should be unzipped into a directory of your choosing. I use
a directory called \TRACE. The program file is called TRACE.EXE and requires
several companion files, namely, EGAVGA.BGI (a graphics driver), and GLASS.
BIN (the file that contains the index of refraction coefficients for over
240 types of Schott glasses). In addition, there are a few design files
which have been ray traced and verified against other people’s work
including "Telescope Optics, Evaluation and Design" by Rutten and van
Venrooij. This book would make a nice companion to this program.


The Design File

TRACE uses an input file, called a design file, to describe the optical
design of the system being simulated. Each design file has an extension .DES
and contains the optical elements and their parameters. Several example
design files are included with this program. They include: a simple
parabolic mirror (NEWT.DES), a medium format camera system of my own design
using a parabolic mirror and a two-lens corrector / focal reducer
(ROWE.DES), a concentric Schmidt Cassegrain camera (CSCT.DES), a
Maksutov-Cassegrain known as a Sigler (SIGLER.DES) and the quintessential
refractor objective, a Fraunhofer doublet (FRAUN.DES). Click here for a
detailed description of the example design files.



The Optical Elements

The design file is organized from top to bottom in the order that you want
the surfaces to reflect, refract, obstruct or form an image. Each element
is on two lines in the file, the first line being the name of the element
and the second line being the parameters for that element.

The elements supported by this version, and their parameters are as follows:

Object
[z] [dia]

This element is the entrance pupil of the system, producing parallel rays
originating at the location [z] and over a circle of diameter [dia]. Every
design file must have this element or the next one as its first element so
that the program knows how to originate the rays. The rays all start
pointing downward, i.e., point in the negative z-direction, just like
they would enter a telescope if that telescope were pointing at the
zenith. This makes visualization easier. This element creates a bundle of
rays, originating at infinity, that uniformly fill the aperture. The
program will propagate these rays until they hit the focal surface.
This element models the rays that come from a source at infinity
(a star) and is therefore most often used to evaluate the performance
of a telescope.

PointSource
[z] [dia] [dist]

This element models a point source of light that is a finite distance away
from the optical system. It will fill the entrance pupil, located at [z],
with a bundle of rays all of which originate at a point that is [dist] away
from the entrance pupil. The entrance pupil has diameter [dia]. In other
words, if your 5" entrance pupil is lcoated at z=12 and you want the
location of the point source to be at z=55, then use parameters 12 5 43.

Refraction
[glass] [z] [ROC]

This element performs refraction from the previous medium to the medium
given by [glass]. The axial location of the refracting surface is given by
[z] and the radius of curvature of the element is given by [ROC]. If the
radius of curvature is positive, then the spherical surface opens upwards,
i.e., the center of curvature is at a point higher on the z-axis than the
surface. If the radius of curvature is negative, then the surface opens
downward. System ray tracing, beginning at the entrance pupil, always
starts in the medium of Air, i.e., has an index of refraction of one.
A valid glass type is Air, which denotes refraction back to a medium with
index of refraction of one. For each wavelength being simulated, the
program automatically calculates the index of refraction from the six
coefficients supplied by Schott. Click here for a list of available glass
types. Notice that refraction through aspherical surfaces is not supported
in this version, except in the form of a Schmidt corrector plate discussed
below.

Mirror
[z] [ROC] [SC] [dia]

This element performs reflection from a surface at the axial location [z]
having a radius of curvature [ROC] and having a Schwartschild constant
[SC]. This constant is the conventional way of describing the asphericity
of a mirror's surface. It is the degree to which the surface has been
deformed away from a sphere, i.e., a sphere has SC=0, a parabola has
SC=-1, a hyperbola has SC less than -1, an oblate ellipsoid has SC
between -1 and 0, and a prolate ellipsoid has SC greater than 0. The
radius of curvature can have either a positive or negative value,
positive denoting a surface opening upward, negative denoting a
surface opening downward, just like the refractive surfaces given
above. Upon reflection, the ray direction is reversed, i.e., if
the ray starts out pointing downward, when reflected it will
point upward and vice versa. The mirror diameter is given by [dia].

Aperture
[z] [dia]

This element is a circular opening having a diameter of [dia] and located
at [z]. It is used for defining the size of lenses and for stopping
undesired optical paths within the optical system. If the user desires
accurate vignetting calculations then careful use of this element is
required.

Obstruction
[z] [dia]

This element is an obstruction in the optical path at location [z] having
a diameter [dia]. It is used to model a circular obstruction, like a
secondary mirror, in the optical path of the telescope.

Annulus
[z] [dia1] [dia2]

This element is equivalent to an Obstruction element with diameter [dia1]
plus an Aperture element with diameter [dia2], both located at [z].

Corrector
[glass] [z] [t] [a] [b] [dia]

This element is a Schmidt corrector plate, where the bottom surface
location is given by [z], having thickness [t] and having a surface
profile on each face of the corrector given by the equation

z = a*rho^2 + b*rho^4.

where z is the surface height of each surface of the corrector plate
and rho is the distance from the z-axis, i.e., from the center of the
corrector plate. The corrector plate material is of type [glass]. The
clear aperture of the corrector plate is [dia]. Make careful note that
the profile defined by a and b is placed on each surface, i.e., the
corrector plate is symmetrical.

FocalPlane
[z]

This element is a flat focal surface at a location given by [z].
Each design file must have either a FocalPlane element or a SphericalFocus
element (described below). All rays are traced to one of these two elements
for calculation of the spot diagrams.

SphericalFocus
[z] [ROC]

This element is a curved focal surface having axial location [z] and
radius of curvature given by [ROC]. As in the above element, all rays
are traced to this surface for spot diagram calculation and presentation.
The radius of curvature can be positive or negative and the same sign
convention is used as in the refractive and reflective elements. Once
again, all design files must have either this element or the above
element as the last optical element in the file.

Wavelength
[lambda1] [lambda2] [lambda3]

This is an optional control statement that defines the wavelengths to be
simulated. The wavelengths are given in microns and the normal range of
the parameters [lambda1] through [lambda3] is 0.4 to 0.8 microns.
Wavelengths outside of these limits will cause the program to extrapolate
the formula for the index of refraction, so, be careful and aware of the
potential inaccuracies in the index of refraction when working outside of
the above wavelength limits.

Angle
[angle1] [angle2] [angle3]

This is an optional control statement that defines the angles used by
the program in simulating the off-axis performance of the system. The
rays are started from the entrance pupil at an angle from the negative
z-axis given by these parameters, i.e., in our telescope pointed at the
zenith, the spot diagrams are calculated for rays entering the system at
the angles given by [angle1] through [angle3]. The angles are given in
radians. One radian is exactly 180/pi degrees (about 57 degrees).

FOV
[size]

This is an optional control statement that defines the size of the spot
diagrams. It is the overall size, edge to edge. The units for [size] are
the same units that are used for the other parameters in the design file.
Be consistent in the units used.

The Simulation Panel

Begin ray tracing by typing TRACE. The program will ask you for the name of
the design file that you wish to ray trace (do not use an extension).
Remember, all design files have .DES as their extension. You will then see
a graphics display with three spot diagrams, a region for changing the
parameters of the optical system, a region containing some useful results
and a hot key menu. Each of these will be covered in the following.


Some Basics

The up and down arrow keys allow you to move around in the display. The
parameters that can be changed are in green and the highlighted parameter
in the blue box is currently active. Typing a valid number will change the
value in the highlighted box. After you have changed all of the parameters
that you wish to change, you can re-simulate the system by hitting the [F1]
key. This will update the spot diagrams and numerical results of the
simulation. Notice that you can change the incident angles in the spot
diagrams and the field of view (FOV), as well as the system parameters
just by moving the highlighted box around.

Spot Diagrams

Three spot diagrams are shown at three different off-axis angles. This
allows you to simultaneously view the spot characteristics at off-axis
angles of interest. I usually set the angle in the first spot diagram to
zero to see the on-axis behavior, the angle in the third diagram to the
corner of the film plane (or the edge of the visual region) and the angle
in the second diagram to some intermediate angle of interest. The amount
of transmitted light at each off-axis angle is also displayed in the
individual spot diagrams. This is the ratio of the number of rays which make
it through the optics to the number of rays that were started at the
entrance pupil.

The scale of the three spot diagrams is given by FOV. This number, which can
be changed by the user, gives the size of the diagrams. In other words, if
FOV = 0.25 then each spot diagram is 0.25 units by 0.25 units overall, and
the distance between the grid lines is 0.025 units. The units can be
anything that you want, but typically they will be either inches or
millimeters. Select a set of units for the element locations, radii, etc.
and be consistent.

Wavelengths

For optical systems that have refractive components it’s necessary to
define the wavelengths of light that will be ray traced. These wavelengths
are given in the panel below the spot diagrams and can be adjusted by the
user. They are always given in microns. The spot diagrams show the results
of tracing these three wavelengths by displaying each spot in three
different colors, red, yellow and green. The wavelength that corresponds
to each color is given in the wavelength control panel.

Parameter Panel

Below the wavelength entry region is the parameter panel. It shows the
optical elements in the design and the parameters associated with these
elements. Most of the parameter labels are self-explanatory, Loc stands
for location, ROC for radius of curvature, SC for the deformation constant
of a mirror, Dia for diameter, etc. Each parameter that can be changed by
the user is shown in green. After the optical parameters are displayed,
the last entry on this panel is the Optimization element. It has two
parameters, Var and NT. Var gives the maximum percentage change of a
parameter during random optimization and NT is the number of trials for
both random and gradient optimization. These two values will be discussed
in more detail under Optimization.

Numerical Display Panel

The second line from the bottom of the display shows several numerical
results and also indicates whether autofocusing is enabled. The first
three items are associated with optimization and the calculation of the
RMS spot diameter and will be discussed under Optimization. The next item
is the effective focal length of the system calculated by sending a ray
through the optics slightly off-axis and then finding the point that this
ray intersects the focal surface. The effective focal length is then
calculated by d/a where d is the intercept distance and a is the off-axis
angle in radians. As usual, the effective focal length has the same units
as those used for the parameters. The last item displayed in this panel
denotes whether autofocusing is ON or OFF.

Hot Key Menu

The hot key menu is shown at the bottom of the simulation panel. The hot
key functions are given in the following:

[F1] - Perform a ray trace. If autofocusing is ON then the program first
calculates the best focal position before performing the ray trace.
Otherwise, it traces to the focal surface given by the focal element
(either FocalPlane or SphericalFocus). If autofocus is ON, the location of
the focal surface is automatically updated with the new value.

[F2] - This toggles the autofocus function ON and OFF.

[F3] - This toggle switch selects or de-selects parameters for optimization.
When selected, the parameter will have a yellow asterisk displayed in front
of it. See the section on Optimization.

[F4]- This hot key invokes random optimization.

[F5] - This hot key invokes gradient optimization.

[F6] - Saves the file to a user specified file name with extension .DES.

[F7} - This hot key allows the user to load a new design file.

[F9] - Pressing this key decrements the highlighted parameter by the
fractional amount given by the Var parameter. As an example, suppose Var =
0.01, and the highlighted parameter is the focal length of a mirror and
equals 60 (inches). Then pressing this key will change the focal length to
60*(1-Var) = 59.4. By changing Var, finer or courser increments of the
variable being adjusted will result.

[F10] - The inverse of F9.

[ESC]- Pressing the escape key will exit the program. Before exiting, the
program will ask if you want to save the current design.

Optimization

Two optimization techniques exist in TRACE, neither of which is very good
without considerable human intervention. They are: random optimization and
gradient optimization. In both cases, the variable(s) to be optimized are
selected and de-selected by first moving the cursor box to the variable of
interest and then pressing the [F3] key. If the parameter is being selected,
a yellow asterisk to appear next to the parameter, and if it is being de-
selected, then the asterisk will disappear. Once all the desired parameters
have been selected, pressing the [F4] key will invoke random optimization
and [F5] will invoke gradient optimization.

The variable labeled NT in the Parameter Panel under Optimize determines the
number of attempts that the program will make for either type of
optimization. At first, when doing random optimization, try NT=100 and if
doing gradient optimization try NT=10.

The variable labeled Var in the Parameter Panel under Optimize determines
the amount that the parameters will be varied during random optimization.
Try setting Var to 0.01 at first. If the program fails to find several
better designs during a trial, set Var to a lower value such as 0.001 or
even smaller.

The optimization algorithm uses an error function defined by:

E = average over the three colors ( average over the three off-axis spots
( RMS spot size) )

which it tries to minimize, so pick your wavelengths and off-axis angles
carefully!

When performing optimization, the program displayes the current RMS spot
size near the bottom of the screen. To the left of this, the program also
displayes the statistics generated by the random optimization routine as
two numbers: Nc/Nt where Nc is the number of times the program found a
better design, and Nt is the total number of trials so far. If, at the end
of a random optimization run, Nc is small or zero, then either the
optimization parameter, Var, is too large or the design cannot be further
improved.

Some Notes on Usage

Use a consistent set of length units for all parameters!

To calculate the off-axis angles that produce certain off-axis distances at
the focal surface, use the formula

A = D/F

where A is the off-axis angle in radians, D is the off-axis distance at the
focal surface, and F is the effective focal length calculated by the program.
D and F must be in the same system of units.

The Airy disk, at the focal plane for a telescope with an f/ratio of f is
given by

d=1.22 * lambda * f

where lambda is the wavelength and d is the diameter of the disk.

Try using the autofocus function when optimizing a design. This can help
the program find a better solution. Be careful with this, as it can cause
the focal length of the design to change in undesirable ways.

Fine focus control can be arranged by changing the Var variable to a small
value such as 1.0e-5, highlighting the focal plane location, and then using
the F9 and F10 keys to increment or decrement the focal surface location.
The F1 key will then resimulate the design.

Return to my home page.