This article is also available in Japanese.

A surface defines the  boundaries between optical materials. Surfaces can be refractive, reflective, diffractive and gradient index. ZEMAX supports more than 65 different surface types, including very general surface shapes like Polynomial surfaces and Biconic Zernikes.

But, it is often the case that a user wants something tailored specifically to his or her own needs, and this is where the user-defined surface is extremely useful and powerful. You can always raise a feature request for us to add a new surface type for you, but ZEMAX also gives you an interface to do this yourself.

The user-defined surface is a compiled function (strictly speaking, a Windows dll) which can implement any surface shape, phase, transmission function, or gradient index, and any combination of these, that you wish. User-defined surfaces can be parametric, or be based on a datafile, or both.

This article describes the steps required to compile a user-defined surface, using the supplied samples as a starting point. It does not address the specific issues involved in coding the surface, which will be described in a separate article.

Producing such a user-defined surface is relatively easy, provided you have a clear mathematical description of how the surface shape is to be defined, and a little programming experience. We provide sample files to make getting started easy. The hard part is always in knowing what the mathematical functions needed to define the surface are!

The first step, therefore, is to define the specification. Find the surface in ZEMAX which is closest to what you want, and read the description in the manual of this surface. Then write out your specification in the same style. Write a text-based description of the surface, then give the sag equation, phase equation etc as required, and list what parameters in the Lens Data Editor and Extra Data Editor do what. Finally, think what the initial values of these parameters should be when the surface is first used. For example, when you first insert a Standard surface, the radius of curvature is infinite, the thickness is zero, and the conic constant is zero. Think what this "safe data" needs to be for your surface.

Then look in the manual again, in the section on the user-defined surface. You will see that there are many supplied example files. Find the sample file that is closest to what you want, and use this as your starting point. By using a supplied sample as your starting point, you will not need to worry about writing all the code that makes your surface talk to ZEMAX: that is already done. You can concentrate solely on programming your surface.

Once you have found the sample file that is closest to your requirements, copy the source file (the file that ends in .c) and give it a new name. In this example, we are going to say that the  sample file us_arrayeven.c is the closest to our requirements. This file is in the {zemaxroot}/dll folder. This surface defines a rectangular array of even-asphere lenslets. Make a copy of this file, and call it myarray.c