Can imported ZMX lens descriptions be reversed?

It's very common for imported aspheric lenses to be facing the wrong way for a model. They can have many parameters so reversing them requires understanding of a whole heirarchy e.g. of aspheric coefficients and how they relate to the surface direction and origin. It would seem that the model understands the whole geometry - does it have a simple way to flip the lens?

Answers (2)

@Colin - can you give the attached code a try and see if it works for you?
(Feel free to DM me if you want to talk more)
opsys = zmximport("ACL12708U-A-Zemax-ZMX.zmx");
opsys.FieldPoints = fieldPoint("Position",[0 0],"ReferenceFrame","Image");
opsys.Wavelengths = 633;
ropsys = reverseSystem(opsys);
subplot(211), h1=view2d(opsys); h1.addRays;
subplot(212), h2=view2d(ropsys); h2.addRays;
It's very common for imported aspheric lenses to be facing the wrong way for a model.
I would like to understand this better, i.e why its common. I would rather this not happen in the first place! If there is a determinstic way to do the right thing, I would like to know.
(Aside - were you using zmximport? )
Here's code for my interpretation of 'facing the wrong way'. The origin (position) and tilt angles are retained.
opsys = zmximport("systemWithAspherics.zmx");
tiledlayout
nexttile
h = view2d(opsys,Labels="surface");
% Assume surface 12 is the aspheric surface.
% Flip sign of the even aspheric terms and the raidus
opsys.Surfaces(12).Aspherics(2:2:end)= -opsys.Surfaces(12).Aspherics(2:2:end);
opsys.Surfaces(12).Radius = -opsys.Surfaces(12).Radius;
nexttile
h = view2d(opsys,Labels="surface");

3 Comments

Thanks Ashish,
That's given me a bit of a steer. If I also reverse the surface order and positions that gets me closer but I may not be able to avoid extracting surfaces and constructing the system programmatically. I had started off trying importing into your new optical design app - specifically the ZMX file from https://www.thorlabs.com/item/ACL12708U-A to model off-axis behaviour from an extended source.
function opsys_rev=load_lens_flip(f)
opsys = zmximport(f);
opsys_rev = copy(opsys);
tiledlayout
nexttile
h = view2d(opsys,Labels="surface");
% Flip sign of the even aspheric terms and the radius
positions = opsys.Surfaces.Position;
offset = max(positions(3:3:end));
opsys_rev.Surfaces(1).Aspherics(2:2:end)= -opsys.Surfaces(2).Aspherics(2:2:end);
opsys_rev.Surfaces(1).Radius = -opsys.Surfaces(2).Radius;
opsys_rev.Surfaces(1).Position = [0 0 offset] - opsys.Surfaces(2).Position;
opsys_rev.Surfaces(2).Aspherics(2:2:end)= -opsys.Surfaces(1).Aspherics(2:2:end);
opsys_rev.Surfaces(2).Radius = -opsys.Surfaces(1).Radius;
opsys_rev.Surfaces(2).Position = [0 0 offset] - opsys.Surfaces(1).Position;
nexttile
h = view2d(opsys_rev,Labels="surface");
end
Being able to import third party models is potentially very helpful to compare different components and approaches however they come in whichever orientation they were exported and potentially in the context of a system. That may be for collimation or focusing and either may be the intended application being modelled. Changing the z order of the object and image planes could also be an option but a method of changing the "sense" of the optical system or components if sufficient information is contained in an imported model without manually reconstructing all the surfaces would make this tool routinely useful.
I think I totally missed your point!
Is the use case to flip the whole system around so light goes 'the other' way? So instead of say, S1->S2->S3 in a doublet, you want light to go from S3->S2->S1?

Sign in to comment.

Products

Release

R2026a

Asked:

on 29 May 2026

Answered:

on 8 Jun 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!