%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% zoomlens.m
% This is simple program for afocal variable zoom lens
% design. System contains three *thin lenses* with
% focal lengths f1, f2, f3 (+,-,+ respectively).
% Inputs :
%          f1,f2,f3 (focal lengths)
%          t1 (dist. between 1 and 2)
% Outputs:
%          t2 (distance between 2 and 3)
%          y3 (final ray height)
%          m  (magnification)
%
% Mar 2020
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear; clc;

% focal lengths
f1 = +300;
f2 = -150;
f3 = +100;

% initial ray height and slope=0
y0 = 1;
u0 = 0;

% distance between initial ray and lens 1
t0 = 10; % arbitrary

% distance between lens 1 and 2,
% this is an array of data such that t1 = {200, 201, ..., 500}
t1 = 200:500;

% Calculations (simple y-u ray tracing)
y1 = y0 + u0.*t0;
u1 = u0 - y1./f1;
y2 = y1 + u1.*t1;
u2 = u1 - y2./f2;

% Final ray height
y3 = u2.*f3;

% distance between lens 2 and 3
t2 = (y3 - y2)./u2;

% magnification
m  = abs(y0./y3);

% to print
[t1' t2' (t1+t2)' m']

% plot (t1 vs t2 and t1 vs m) data
subplot(2,1,1); plot(t1,t2)
subplot(2,1,2); plot(t1,m)
