%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% achromate.m
% Simple achromatic thin lens design
% 
% Inputs:
%         f  Focal length of system
%     index  Refractive indices (FdC) of glasses
%         V  Abbe value of glasses
% Outputs:
%      EFFL  For each F, d, C lines
%        df  Axial chormatic shift C-F lines
%         R  Radii of curvatures
%
% Nov 2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear; clc;
% inputs
f = 300;
index = [1.5224 1.5168 1.5143; ... % first  lens
         1.6875 1.6727 1.6667];    % second lens
V     = [64.17 32.25];

% calculations
P  = 1/f;
P1 = P*(-V(1)/(V(2)-V(1)));
P2 = P*(+V(2)/(V(2)-V(1)));
n1 = index(1,2);
n2 = index(2,2);
K1 = P1/(n1-1);
K2 = P2/(n2-1);

R11 = f/2;
R12 = -R11;
R21 = R12;
R22 = R12/(1-K2*R12);

phi1= (index(1,1)-1)*(1/R11-1/R12);
phi2= (index(2,1)-1)*(1/R21-1/R22);
fC  = 1/(phi1+phi2);

phi1= (index(1,3)-1)*(1/R11-1/R12);
phi2= (index(2,3)-1)*(1/R21-1/R22);
fF  = 1/(phi1+phi2);

df = fF-fC;

R = [R11 R12 R21 R22];

fprintf('System Focal Length for F-line  = %f\n',fF)
fprintf('System Focal Length for d-line  = %f\n',f)
fprintf('System Focal Length for C-line  = %f\n',fC)
fprintf('Axial chormatic shift F-C lines = %f\n',df)

perf = P1*V(2) + P2*V(1);
fprintf('Performance P1*V2 + P2*V1       = %f\n',perf)

fprintf('Radius of Curvatures:\n')
for i=1:length(R)
    fprintf('%f\n',R(i))
end

%////////////////////////////////////////////////////
% Example output
%
% System Focal Length for F-line  = 284.125040
% System Focal Length for d-line  = 300.000000
% System Focal Length for C-line  = 283.813194
% Axial chormatic shift C-F lines = 0.311846
% Performance P1*V2 + P2*V1       = 0.000000
% Radius of Curvatures:
% 150.000000
% -150.000000
% -150.000000
% -602.307061
%
%////////////////////////////////////////////////////

