The first step in writing a user-defined surface is to describe the shape of the surface with an equation of the form

z = f(x, y)

In this article I will use Waterloo Maple to enter the required equations and produce the optimized C-code needed. In the following examples, red courier font represents data entered into Maple, blue font represents output from Maple, and text after the # symbol are comments.

In the following, the variable ka is the amplitude of a Gaussian function of fixed width, rr is the radial distance at which the amplitude has fallen to ka/100, and dx and dy are optional decentrations entered via the Lens Data Editor.



Maple input/output


This function is then added to the normal Odd Asphere sag as defined in the ZEMAX manual. By using Maple this can be easily done with common math functions and procedures:

The Gaussian sag added tot he Odd Asphere sag

This equation must be converted to C code to implement adequate DLL for Zemax. Maple has very convenient tool for this action namely “Codegen”.  Note, that array indexes are decreased by 1 when Maple performs C code generation – that’s why there is param[i+1] in the Maple code:

Code Generated by Maple

What's more, Maple can also optimize the C-code it produces:

OPtimized C-code produced by Maple

This can then be copy-and-pasted into Case 5 of the DLL, with just a little hand editing.