trace chief ray

Contents

% load lens
clear
load kidger

trial axial ray

pos_in = [0 pya(1,1) 0];
dir_in = [0 0 1];
raytrace(pos_in,dir_in,cv,th,rn);
   n         X         Y         Z      kx      ky      kz         OPL
   0     0.000     6.250     0.000  0.0000  0.0000  1.0000
   1     0.000     6.250     1.081  0.0000 -0.2161  1.6059  1.08095444
   2     0.000     6.054     0.040  0.0000 -0.2078  0.9782  2.38514582
   3     0.000     5.058    -0.430  0.0000 -0.0955  1.6336  4.79142914
   4     0.000     4.935     0.667  0.0000  0.0797  0.9968  3.43728438
   5     0.000     4.979     0.000  0.0000  0.0797  0.9968  0.54215402
   6     0.000     5.316     0.209  0.0000  0.0306  1.6201  4.22983074
   7     0.000     5.347    -0.655  0.0000 -0.1256  0.9921  2.65142083
   8     0.000    -0.002     0.000  0.0000 -0.1256  0.9921

trial chief-ray

pos_in = [0 pyc(1,1) 0];
theta = 22*pi/180;
dir_in = [0 sin(theta) cos(theta)];
raytrace(pos_in,dir_in,cv,th,rn);
   n         X         Y         Z      kx      ky      kz         OPL
   0     0.000    -4.670     0.000  0.0000  0.3746  0.9272
   1     0.000    -4.451     0.540  0.0000  0.5239  1.5334  0.58267803
   2     0.000    -3.776     0.015  0.0000  0.5184  0.8551  3.38235467
   3     0.000    -0.664    -0.007  0.0000  0.5028  1.5572  6.00384731
   4     0.000    -0.338     0.003  0.0000  0.4904  0.8715  1.73749257
   5     0.000     0.339     0.000  0.0000  0.4904  0.8715  1.38140915
   6     0.000     2.623     0.051  0.0000  0.4639  1.5526  4.65609292
   7     0.000     3.281    -0.244  0.0000  0.3705  0.9288  3.72879815
   8     0.000    19.976     0.000  0.0000  0.3705  0.9288

exercise 1

'differential' trace and Newton-Raphson to trace ray through center of pupil

aim = pyc(1,1);
theta = 22*pi/180;
dir_in = [0 sin(theta) cos(theta)];
pos_in = [0 aim 0];
[pos dir] = raytrace(pos_in,dir_in,cv,th(1:ast),rn);
fz = pos(2);
fprintf('%2s %10s %10s\n','#','Y','aim');
delta = 1e-3 * pya(1,1);
fprintf('%2d %10.6f %10.6f\n',0,fz,aim);
for k=1:20
    pos_in = [0 aim+delta 0];
    [pos dir] = raytrace(pos_in,dir_in,cv,th(1:ast),rn);
    diff = (pos(2) - fz)/delta;
    aim = aim - fz/diff;
    pos_in = [0 aim 0];
    [pos dir] = raytrace(pos_in,dir_in,cv,th(1:ast),rn);
    fz = pos(2);
    fprintf('%2d %10.6f %10.6f\n',k,fz,aim);
    if abs(fz)<1e-7
        break;
    end
end
 #          Y        aim
 0   0.339474  -4.669695
 1  -0.001397  -5.129706
 2   0.000000  -5.127829
fprintf('\n chief ray (through center of pupil)\n\n');
raytrace(pos_in,dir_in,cv,th,rn);
 chief ray (through center of pupil)

   n         X         Y         Z      kx      ky      kz         OPL
   0     0.000    -5.128     0.000  0.0000  0.3746  0.9272
   1     0.000    -4.866     0.648  0.0000  0.5376  1.5286  0.69837066
   2     0.000    -4.208     0.019  0.0000  0.5313  0.8472  3.21496309
   3     0.000    -0.996    -0.017  0.0000  0.5078  1.5556  6.04515152
   4     0.000    -0.660     0.012  0.0000  0.4836  0.8753  1.77002922
   5     0.000     0.000     0.000  0.0000  0.4836  0.8753  1.36556977
   6     0.000     2.234     0.037  0.0000  0.4612  1.5534  4.62008157
   7     0.000     2.909    -0.192  0.0000  0.3781  0.9258  3.83932725
   8     0.000    19.978     0.000  0.0000  0.3781  0.9258
Uin = theta;
Qin = aim*cos(Uin);
trig_ray(Qin,Uin,cv,th,rn);
 n            Y     n sin(U)
 1     -4.86621      0.53756
 2     -4.20802      0.53134
 3     -0.99602      0.50775
 4     -0.66037      0.48359
 5      0.00000      0.48359
 6      2.23422      0.46116
 7      2.90853      0.37808
 8     19.97790      0.37808

exercise 2

% Coddington trace
N = 20;
fields = zeros(N+1,4);
for n=0:N
   h = n/N;
   u = h*22;
   fields(n+1,1:2) = [h u];
   theta = u*pi/180;
   Y = h*pyc(1,1);
   % Y = aim_ray(h*aim,theta,cv,th(1:ast),rn);
   fields(n+1,3:4) = codd_ray(Y*cos(theta),theta,cv,th,rn);
end

fprintf('%10s%10s%10s%10s\n','h','U','tan shift','sag shift');
disp(fields)
         h         U tan shift sag shift
         0         0    0.2299    0.2299
    0.0500    1.1000    0.2294    0.2270
    0.1000    2.2000    0.2277    0.2184
    0.1500    3.3000    0.2250    0.2042
    0.2000    4.4000    0.2214    0.1845
    0.2500    5.5000    0.2172    0.1598
    0.3000    6.6000    0.2126    0.1303
    0.3500    7.7000    0.2078    0.0965
    0.4000    8.8000    0.2030    0.0590
    0.4500    9.9000    0.1983    0.0185
    0.5000   11.0000    0.1938   -0.0243
    0.5500   12.1000    0.1893   -0.0684
    0.6000   13.2000    0.1840   -0.1128
    0.6500   14.3000    0.1772   -0.1563
    0.7000   15.4000    0.1669   -0.1976
    0.7500   16.5000    0.1507   -0.2351
    0.8000   17.6000    0.1248   -0.2670
    0.8500   18.7000    0.0836   -0.2912
    0.9000   19.8000    0.0195   -0.3055
    0.9500   20.9000   -0.0784   -0.3070
    1.0000   22.0000   -0.2248   -0.2925

Results from ZEMAX
Y Angle (deg)	      Tan Shift	      Sag Shift	    Real Height	    Ref. Height	     Distortion
    0.00000000	     0.22999260	     0.22999260	     0.00000000	     0.00000000	     0.00000000	%
    1.10000000	     0.22950749	     0.22712745	     0.95548619	     0.95549421	    -0.00083993	%
    2.20000000	     0.22804559	     0.21857114	     1.91162863	     1.91169323	    -0.00337909	%
    3.30000000	     0.22569174	     0.20444154	     2.86908367	     2.86930392	    -0.00767585	%
    4.40000000	     0.22258058	     0.18493664	     3.82850786	     3.82903734	    -0.01382811	%
    5.50000000	     0.21888554	     0.16033694	     4.79055792	     4.79161085	    -0.02197425	%
    6.60000000	     0.21480221	     0.13100882	     5.75589080	     5.75775024	    -0.03229458	%
    8.80000000	     0.20621464	     0.06009117	     7.69903249	     7.70368556	    -0.06040058	%
    9.90000000	     0.20195541	     0.01971176	     8.67815390	     8.68499565	    -0.07877663	%
   11.00000000	     0.19769643	    -0.02295929	     9.66318208	     9.67290481	    -0.10051506	%
   11.22000000	     0.19682630	    -0.03169217	     9.86095395	     9.87134879	    -0.10530321	%
   11.44000000	     0.19594327	    -0.04047361	    10.05899336	    10.07009531	    -0.11024673	%
   11.66000000	     0.19504339	    -0.04929561	    10.25730552	    10.26915093	    -0.11534949	%
   11.88000000	     0.19412219	    -0.05814993	    10.45589560	    10.46852225	    -0.12061548	%
   12.10000000	     0.19317453	    -0.06702809	    10.65476877	    10.66821593	    -0.12604879	%
   13.20000000	     0.18781099	    -0.11146279	    11.65356137	    11.67175498	    -0.15587725	%
   14.30000000	     0.18057413	    -0.15507654	    12.66020048	    12.68437389	    -0.19057631	%
   15.40000000	     0.16979637	    -0.19650638	    13.67531632	    13.70695362	    -0.23081203	%
   16.50000000	     0.15293022	    -0.23418702	    14.69952333	    14.74040736	    -0.27736026	%
   18.70000000	     0.08428453	    -0.29082195	    16.77753721	    16.84377218	    -0.39323122	%
   19.80000000	     0.01950904	    -0.30529168	    17.83239776	    17.91570366	    -0.46498814	%
   20.90000000	    -0.07868639	    -0.30692140	    18.89840730	    19.00255835	    -0.54808961	%
   22.00000000	    -0.22486754	    -0.29241758	    19.97584459	    20.10546871	    -0.64472067	%
plot(fields(:,3),fields(:,1),'k',fields(:,4),fields(:,1),'k--','LineWidth',2);
ylabel('fractional field');
xlabel('shift');

exercise 3

del = 0.1;
h = 1;
theta = h*22*pi/180;
dir_in = [0 sin(theta) cos(theta)];
pos_in = [0 h*pyc(1,1) 0];
[pos dir] = raytrace(pos_in,dir_in,cv,th,rn);
yh = pos(2);
tanuh = dir(2)/dir(3);

fprintf('image height %g fractional height %g\n',yh,h);
image height 19.9758 fractional height 1
% tangential focus
pos_in = [0 h*pyc(1,1)+del 0];
[pos dir] = raytrace(pos_in,dir_in,cv,th,rn);

fprintf('\ntangential focus\n');
dy = pos(2)-yh;
du = dir(2)/dir(3) - tanuh;
fprintf('dy %g  du %g\n',dy,du);
fprintf('solve %g\n',-dy/du);
tangential focus
dy -0.000464773  du -0.00205744
solve -0.225898
% sagittal focus
pos_in = [del h*pyc(1,1) 0];
[pos dir] = raytrace(pos_in,dir_in,cv,th,rn);

fprintf('\nsagittal focus\n');
tanv = dir(1)/dir(3);

fprintf('dx %g  dv %g\n',pos(1),tanv);
fprintf('solve %g\n',-pos(1)/tanv);
clear dy du tanuh tanv
sagittal focus
dx -0.000594109  dv -0.00203087
solve -0.292539

exercise 4

% tangential fan
ya = linspace(-1,1,41);
fprintf('%10s %10s %10s\n','rel ap','y','x');
for k=1:length(ya)
    pos_in = [0 pyc(1,1)+ya(k)*pya(1,1) 0];
    [pos dir] = raytrace(pos_in,dir_in,cv,th,rn);
    yr(k) = pos(2) - yh;
    xr(k) = pos(1);
    fprintf('%10.2f %10.4f %10.4f\n',ya(k),yr(k)*1e3,xr(k)*1e3);
end
    rel ap          y          x
     -1.00  -132.6919     0.0000
     -0.95  -103.6311     0.0000
     -0.90   -79.8058     0.0000
     -0.85   -60.3453     0.0000
     -0.80   -44.5339     0.0000
     -0.75   -31.7797     0.0000
     -0.70   -21.5901     0.0000
     -0.65   -13.5528     0.0000
     -0.60    -7.3212     0.0000
     -0.55    -2.6029     0.0000
     -0.50     0.8498     0.0000
     -0.45     3.2473     0.0000
     -0.40     4.7689     0.0000
     -0.35     5.5678     0.0000
     -0.30     5.7754     0.0000
     -0.25     5.5048     0.0000
     -0.20     4.8537     0.0000
     -0.15     3.9072     0.0000
     -0.10     2.7397     0.0000
     -0.05     1.4176     0.0000
      0.00     0.0000     0.0000
      0.05    -1.4586     0.0000
      0.10    -2.9075     0.0000
      0.15    -4.2980     0.0000
      0.20    -5.5823     0.0000
      0.25    -6.7119     0.0000
      0.30    -7.6364     0.0000
      0.35    -8.3019     0.0000
      0.40    -8.6494     0.0000
      0.45    -8.6137     0.0000
      0.50    -8.1208     0.0000
      0.55    -7.0866     0.0000
      0.60    -5.4143     0.0000
      0.65    -2.9921     0.0000
      0.70     0.3100     0.0000
      0.75     4.6437     0.0000
      0.80    10.1860     0.0000
      0.85    17.1441     0.0000
      0.90    25.7615     0.0000
      0.95    36.3239     0.0000
      1.00    49.1680     0.0000
idx = find(ya>-0.55);
plot(ya(idx),yr(idx)*1e3,'k','LineWidth',2);
grid();
xlabel('relative aperture');
ylabel('ray error (\mum)');
% sagittal fan
ya = linspace(-1,1,41);
yr = zeros(size(ya));
xr = yr;
fprintf('%10s %10s %10s\n','rel ap','y','x');
for k=1:length(ya)
    pos_in = [ ya(k)*pya(1,1) pyc(1,1) 0];
    [pos dir] = raytrace(pos_in,dir_in,cv,th,rn);
    yr(k) = pos(2) - yh;
    xr(k) = pos(1);
    fprintf('%10.2f %10.4f %10.4f\n',ya(k),yr(k)*1e3,xr(k)*1e3);
end
    rel ap          y          x
     -1.00    -4.7092    13.8208
     -0.95    -3.6217    20.7816
     -0.90    -2.7551    25.2615
     -0.85    -2.0686    27.8251
     -0.80    -1.5288    28.9255
     -0.75    -1.1083    28.9263
     -0.70    -0.7845    28.1174
     -0.65    -0.5389    26.7294
     -0.60    -0.3559    24.9437
     -0.55    -0.2229    22.9018
     -0.50    -0.1291    20.7118
     -0.45    -0.0656    18.4549
     -0.40    -0.0253    16.1894
     -0.35    -0.0019    13.9553
     -0.30     0.0094    11.7773
     -0.25     0.0127     9.6681
     -0.20     0.0113     7.6299
     -0.15     0.0077     5.6574
     -0.10     0.0039     3.7392
     -0.05     0.0010     1.8596
      0.00     0.0000     0.0000
      0.05     0.0010    -1.8596
      0.10     0.0039    -3.7392
      0.15     0.0077    -5.6574
      0.20     0.0113    -7.6299
      0.25     0.0127    -9.6681
      0.30     0.0094   -11.7773
      0.35    -0.0019   -13.9553
      0.40    -0.0253   -16.1894
      0.45    -0.0656   -18.4549
      0.50    -0.1291   -20.7118
      0.55    -0.2229   -22.9018
      0.60    -0.3559   -24.9437
      0.65    -0.5389   -26.7294
      0.70    -0.7845   -28.1174
      0.75    -1.1083   -28.9263
      0.80    -1.5288   -28.9255
      0.85    -2.0686   -27.8251
      0.90    -2.7551   -25.2615
      0.95    -3.6217   -20.7816
      1.00    -4.7092   -13.8208
plot(ya,yr,'b--',ya,xr,'k','LineWidth',2);
grid
xlabel('relative aperture');
ylabel('ray error (\mum)');