HarrisonKramer / optiland

Comprehensive optical design, optimization, and analysis in Python.
https://optiland.readthedocs.io/
MIT License
90 stars 19 forks source link

[Bug] Spot Diagram with Rotated Image Plane #68

Closed manuelFragata closed 1 month ago

manuelFragata commented 1 month ago

Describe the bug When designing systems in which the image plane is tilted/rotated, the spot diagram sometimes represents the data we don't want.

To Reproduce Steps to reproduce the behaviour, simply setup a system for which the image plane is rotate about one of its axes:

import numpy as np
import matplotlib.pyplot as plt
import optiland
from optiland.materials import Material, IdealMaterial, AbbeMaterial
from optiland import optic, analysis, optimization

# Initiate the optical system
lens = optic.Optic()

# Set the system settings
wvl = 0.355
lens.set_aperture(aperture_type='EPD', value=8.0)
lens.set_field_type(field_type='angle')
lens.add_field(y=0)
lens.add_wavelength(value=wvl, is_primary=True)

# Setup the LDE data
lens.add_surface(index=0, radius=np.inf, z=-np.inf)
lens.add_surface(index=1, z=-40)
lens.add_surface(index=2, z=-20, is_stop=True)
lens.add_surface(index=3, x=0, y=0, z=0, ry=np.pi/4, material="mirror", surface_type="standard") # M1
lens.add_surface(index=4, x=-15, y=0, z=0, ry=-np.pi/4, rx=np.pi/2, material="mirror", surface_type="standard") # M2
lens.add_surface(index=5, x=-15, y=20, z=0, rx=np.pi/2) # Image plane

lens.draw3D()

spot = analysis.SpotDiagram(lens)
spot.view()

Expected behavior If correctly defined, the spot diagram should take into account the local (rotated, e.g) coordinates of the image plane, and not the global ones.

Screenshots

This is what the system looks like:

Image

This is what the wrong spot diagram will look like:

Image

Environment

Additional Comments Creating a PR soon with the bug fix.

HarrisonKramer commented 1 month ago

Thanks for opening this issue and glad to hear you're working on a fix.

I see the visualization shows a bug as well - the rays look okay, but the second mirror is not positioned correctly. If you're focusing on the spot diagram bug, then I can look into the visualization issue. In any case, I'll wait for your PR before proceeding.

Kramer

manuelFragata commented 1 month ago

Thanks for opening this issue and glad to hear you're working on a fix.

I see the visualization shows a bug as well - the rays look okay, but the second mirror is not positioned correctly. If you're focusing on the spot diagram bug, then I can look into the visualization issue. In any case, I'll wait for your PR before proceeding.

Kramer

Hi Kramer,

Yes, actually I was also going to create another bug issue, because of the incorrect surface rendering. For that one though, I could not manage to find a solution, so maybe you can help?

Just submitted the PR.

Manuel

HarrisonKramer commented 1 month ago

Yes, no problem. I'll look into this one! Hopefully a simple fix.

Kramer