Engineering
Lens design & the optimiser
Designing a lens is choosing surfaces that satisfy several demands at once. Photonica does it the way commercial design codes do: a merit function, and damped least squares to minimise it.

How it works
You give the optimiser two lists. Variables are the things it may change. Operands are the things you want to be true. Every operand contributes weight × (value − target) to the merit function; spot-size operands add one residual per traced ray. The solver then walks downhill until it cannot improve further.
Variables
| Variable | Changes |
|---|---|
| curv1 / curv2 | The curvature (1/R) of the front or back surface. Bounded so the surface still covers the aperture |
| thickness | Centre thickness, keeping the front vertex fixed |
| axial | Position along the part’s own optical axis |
| conic1 / conic2 | Conic constant of a surface — how aspheric it is |
| a4_1 / a4_2 | The fourth-order aspheric term |
| tilt / pitch | Yaw and pitch of the element |
| screen_axial | Where the screen sits — the classic refocus compensator |
Operands
| Operand | Targets |
|---|---|
| spot_screen | RMS spot size on a screen. Target 0 for the sharpest possible image |
| spot_best_focus | RMS spot at the system’s own best focus, ignoring where the screen is |
| efl | Effective focal length in mm |
| collimation | Spread of the outgoing ray angles — target 0 for a perfectly parallel output |
| width_ratio | Output beam width ÷ input width, for beam expanders |
| beam_deviation | How far the beam has been turned, in degrees |
| chromatic_focus | Blue-minus-red focal shift. Target 0 to make an achromat |
A worked example
To build an achromatic doublet — a lens with a chosen focal length and no first-order colour error:
- Put a positive crown-glass lens and a negative flint-glass lens close together on the beam.
- Add variables:
curv1andcurv2on both elements. - Add operands:
eflwith your target focal length,chromatic_focustargeting 0, andspot_best_focustargeting 0 to keep it sharp. - Give the focal length a low weight (0.05 is enough — it is easy to hit) and the others 1.
- Press OPTIMISE.
The merit log shows the value falling per iteration. Demo 16 does exactly this and improves the merit by a factor of 1320 in seven iterations. Undo puts the design back if you do not like where it went.