Most surfaces can be represented in implicit form by F(x,y,z) = 0.  As described in book [2], the normal vector N to surface at point (x0,y0,z0) is proportional to partial derivatives of F(x,y,z) at this point.  The normal vector is:

Equation for the normal vector

ZEMAX gives the point of intersection ray with flat facet (x1,y1,z1) and the direction cosines of ray (l,m,n), while the user provides distance t from point (x1,y1,z1) to actual surface ray intersection point (x0,y0,z0) and the normal vector components.

Ray equations are xR = x1 + lt, yR = y1 + mt, zR = z1 + nt. At the intersection point, F(x1 + lt, y1 + mt, z1 + nt) = F(t) = 0 (one variable equation).  The following Newton algorithm can be used to solve it:

Newton algorithm used to solve ray equations

where tk+1 is the next approximation for t. If  |tk - tk+1| < e, where e is a user-defined small number, the equation is solved (more complex iterators may be needed for more complex surface shapes). A variable t derivative can be written as:

Derivative term needed for Newton algorithm

Note: vector components must be normalized before sending to ZEMAX.

In a Cartesian coordinate system, any implicit curve can be easily rotated about the z-axis.  The equation curve y = f(z) describes the curve.  When rotated, the surface of revolution is assumed to be a set of round circumferences along the z-axis, with radii Ri = f(z).  The circle equation is R2 = x2 + y2 and the surface of revolution is F(x,y,z) = f(z)2 - x2 - y2 = 0.

As an example, let’s use a cubic spline curve.  A cubic spline is a piecewise curve with y = f(x), which interpolates any smooth curve defined by the set of points (the curve is through a set of points S = {(x1,y1) ... (xN,yN)}).  Each piece of cubic spline is a cubic polynomial and lays between two neighboring points: (xi+1,yi+1) and (xi,yi).  Note that x point values must be placed in ascending order, i.e. xi < xi+1.  The disadvantage of cubic splines is that they are inclined to oscillation in the neighborhood of the point if it is considerably different from its neighbors.  More information can be found in [5], other literature, and on the web.

Below, the shown object is based on a cubic spline (file c_spline.zmx).  All points are in ascending order but oscillation appears.  Note that Bezier curves described above are free from oscillations.  A cubic spline can be easily modeled in most CAD software.

User-defined object based on a cubic spline curve

Close-up of oscillations in cubic spline