How to Create Surfaces of Revolution via User Defined Objects in Zemax

Introduction

Within non-sequential mode Zemax allows us to use different types of objects in design: lenses, aspheres, cylinders, blocs, and others. But sometimes the user can’t find the appropriate object. For this, there is a feature allowing create your own object for advanced users.  

There is “User Definer Object” in the object type list. This object represented by DLL (Dynamic Link Library). It can be written in C programming language (or C++ also). The advantages of these objects as described in [1]:

 

  • DLL defined objects generally ray trace much faster, and with much higher numerical precision, than objects imported from CAD programs.
  • Any number of complex curved shapes may be combined in a single object, unlike the polygon object which only has flat faces.
  • Objects may have a mixture of reflective and refractive curved faces, with user-definable face names.
  • The DLL description is inherently parametric, which means the object is dynamically regenerated when any defining property is modified. This allows interactive design, modification, and even optimization.
  • User-defined coating data, including detailed control over the complex amplitude reflection and transmission coefficients, is supported. Coating data may be ray position, cosine, or object coordinate dependent.

 

Below we’ll consider some sample Zemax DLLs and DLL with a surface of revolution of Bezier curve, also some mathematics for calculating ray-surface intersection.

 

 

Sample Zemax DLLs and implicit surfaces

Most surfaces can be represented in implicit form . For raytrace we must found an intersection point of the ray with the surface, also find normal vector to surface in this point.

We can see two user DLLs with C code in folder \Zemax\Object\Dll\UserObjects - Half cylinder and Elliptical volume. These DLLs creates a solid bodies shown below:

 

 

Each object has flat front and rear surfaces, and user-defined side surface. In DLL first, we must create a set of flat triangular facets for approximating the object. This approximation uses for object drawing and also gives us the starting point for finding a ray-surface intersection point.

 

 

Normal vector  to surface at point  proportional to partial derivatives of  at this point as described in the book [2]. So we have a normal vector . Zemax gives us the following data: point of intersection ray with flat facet  and direction cosines of ray . From us it require distance  from point  to actual surface ray intersection point and normal vector components. Ray equations are , , . Therefore at the intersection point, we must have . In sample DLLs code there is a description of a simple Newton iteration process for finding and normal vector components. Note: vector components must be normalized before sending it to Zemax. Also in sample DLL code other information concerned C language routines and details can be found.

 

 

Bezier DLL and parametric surfaces

Some surfaces can’t be represented in implicit form. But they can be parametric. I.e. each point of these surfaces satisfy equations [3]: , where  - parameters of the surface. Normal vector to surface at point , , is defined by the cross product .

Ray equations are . Here  are ray coordinates at flat triangular facet,  are ray direction cosines. At ray-surface intersection point, we must have , , . So we obtained a system of equations , , and three unknown parameters . If we solve them we will got a distance to the actual surface and normal vector.

For demonstration we choose the revolution surface of Bezier curve as the side surface, front and rear are still flat. Bezier curve is a parametric curve defined by the following equations [4]: , where , . Here  are the control points of the Bezier curve, the total number of points is . With two dimensional curves, we have . For curve revolve we must include parameter v, so the surface of revolution is . Notice that these three equations correct for other curves in general. Revolution surface of Bezier curve and native curve are shown above:

 

          

 

Further, we must solve the system of equations described above. We can use the Newton method described in [5]. Put , where . Then next iteration root is , where -1 power denotes inverse matrix and  detotes jacobian of :

 

.

When , where  is user-defined small number we will have a solution for this system. But pay attention to choosing a starting point for the Newton method. With periodic function, we can have an incorrect result.

 

 

User DLLs and imported objects

User-defined DLL sample for Bezier-based object can be found in the archive at last page of this article. The filename is bezier_r.dll, also C code includes in file bezier_r.c. Note that bezier.dll compiled for SSE2 processor instruction set (CoreDuo or newer processors), if you have older you can compile bezier_r.c for your system yourself. Parameters 1 and 2 specify the facets numbers, parameters from 3 to 22 specify control points data.

Now we create in Zemax Bezier object same as shown above and set 10 radial and 10 angular facets with Source ellipse:

 

 

As we can see rays refract not at facets, but on exact surface geometry. Then if we increase the number of facets picture looks more pretty:

 

 

And we can export user defined objects from Zemax to CAD formats (SAT, STEP or IGES). But pay attention that the resulting file not smooths the surface, but only set of facets. For obtaining exact solid geometry we can use external CAD software, for example, Rhino3D, KOMPAS, AutoCAD, ProEngineer etc. And set Bezier curve points manually, then rotate and export to CAD file or save for future work.

Then we create file bezier_r.sat in CAD software. And run raytrace for DLL object and imported object with 1 million rays (test.zmx and testCAD.zmx files). Also, we will check memory usage. We used AMD 3950X processor for analysis and OpticsStudio 20.3. Results in the table below. There is an amazing raytracing speed!

 

 

DLL

Imported in Kernel mode

Imported in Standard mode

Memory usage, Mb

563

1142

928

Raytrace time, sec

5.1

318

7.78

 

Optimization is possible for user defined objects. We can set control points as variables. Just try to improve focusing properties of our object. See file optimize.zmx. After optimization we have this object, like free-form:

 

Using the custom surface of revolution in Zemax

Such surfaces above could be used for designing freeform lenses like RXI lens, TIR lens, and reflectors with or without facets.

  

Summary and Attachments

We considered Zemax capability – use User Defined Objects and how this object can be realized. It works faster than imported object. We showed the object based on revolution surface of Bezier curve, but each user, who is sophisticated in programming, can describe your own object and optimize it within Zemax.

 

 

 

References

  1. Zemax User’s Guide
  2. A. Korn, T.M. Korn. Mathematical handbook for scientists and engineers, McGraw-Hill, 1968.
  3. Shirley, R. K. Morley. Realistic Ray Tracing 2nd ed., A K Peters, 2003
  4. Piegl, W.Tiller. The NURBS book, Springer, 1996
  5. William H. Press et all., Numerical Recipes. The Art of Scientific Computing 3rd, Cambridge University Press, 2007