Skip to main content
Solved

Problem with grid sag in OpticStudio

  • February 16, 2022
  • 2 replies
  • 193 views

RosaVA

Hello, my problem is the following:


I would like to create a spherical surface (z=r-sqrt(r^2-(x2.^2)-(y2.^2))) using grid sag. Firstly, I created a MATLAB script to generate the .dat file which contains the surface info with this aspect:

nx ny delx dely unitflag xdec ydec
z dz/dx dz/dy d2z/dxdy nodata
.
.

The problem is that when I import the file to Zemax, it creates a surface like this one instead of a sphere:

My MATLAB Code:

%% Generating the sphere
x=linspace(-5,5,1000);
y=linspace(-5,5,1000);
[x2,y2]=meshgrid(x,y);
r=40; %radius (mm)
z=r-sqrt(r^2-(x2.^2)-(y2.^2)); %Equation

%% Zemax file
%Vector definition (nx ny delx dely unitflag(mm) decx decy)
dat=[1000 1000 0.01 0.01 0 0 0];
%z y derivatives vector:
dzdx=zeros(1000000,1);
dzdy=zeros(1000000,1);
dzdxdy=zeros(1000000,1);
nodata=zeros(1000000,1);
z_columna=reshape(z,1000000,1);

dato=[z_columna dzdx dzdy dzdxdy nodata];

%File creation (.dat):
eval(['fid=fopen("esfera40.dat", ''w'');']);
fprintf(fid, '%d %d %1.10g %1.10g %1.f %1.f %1.f \n', dat(1), dat(2), dat(3), dat(4), dat(5), dat(6), dat(7));
fprintf(fid, '%0.20g %d %d %d %d\n', dato);
fclose(fid);

Best answer by Allie

Hi @RosaVA - I wrote a Knowledgebase article on this topic in 2020. It provides Matlab code for generating a DAT file with a given equation. Perhaps that could help? The article is here: How to write a Grid Sag DAT file programmatically – Knowledgebase (zemax.com)

View original
Did this topic help you find an answer to your question?

2 replies

Jeff.Wilde
Luminary
Forum|alt.badge.img+3
  • Luminary
  • 505 replies
  • February 16, 2022

Try a very simple modification of your second fprintf statement (replacing the array “dato” with its transpose):

fprintf(fid, '%0.20g %d %d %d %d\n', dato');

 


Allie
Zemax Staff
Forum|alt.badge.img+2
  • Zemax Staff
  • 343 replies
  • Answer
  • February 18, 2022

Hi @RosaVA - I wrote a Knowledgebase article on this topic in 2020. It provides Matlab code for generating a DAT file with a given equation. Perhaps that could help? The article is here: How to write a Grid Sag DAT file programmatically – Knowledgebase (zemax.com)


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings