PCLENS Demonstrates ray tracing through a plano--convex lens
Demonstration is done by ray tracing using raysphere;
SYNTAX: pclens:
See also; RAYSPHERE, ABDEMO
by Chuck DiMarzio Northeastern University April 2009
!! This file may be copied, used, or modified for educational and !! research purposes provided that this header information is not !! removed or altered, and provided that the book is cited in !! publications, as DiMarzio, Charles A., Optics for Engineers, !! CRC Press, Boca Raton, FL, 2011. !! http://www.crcpress.com !! Other distribution is prohibited without permission.
Contents
Set up parameters for the problem
zstart=-1; % Starting location for rays r=2; % radius of sphere th=0.5; % Thickness of lens pc=[0,0,r]'; % sphere center n=1.5; % index of refraction of glass endplane=5; % end plane for displaying rays % zplot=[];xplot=[]; % arrays for plot variables % hmax=1; % Maximum height of ray above lens vertex
Trace rays exactly from infinite object through curved and flat surfaces
for h=(0:0.2:1)*hmax; % Loop on rays: h is height above vertex p0=[h,0,zstart]'; % p0 is the starting point v=[0,0,1]'; v=v/sqrt(v'*v); [s1,s2]=raysphere(p0,pc,v,r); p1=p0+s1*v; % p1 is on the first surface nor=-(p1-pc)/sqrt((p1-pc)'*(p1-pc)); % Unit normal nr=n; % relative index of refraction vnew=v/nr+(sqrt(1-(1/nr)^2*(1-(v'*nor)^2))-v'*nor/nr)*nor; v=vnew; p2=p1+vnew/vnew(3)*(th-p1(3)); % p2 is on the second (flat surface) nor=[0,0,1]'; % Second surface nr=1/n; % relative index of refraction vnew=v/nr+(sqrt(1-(1/nr)^2*(1-(v'*nor)^2))-v'*nor/nr)*nor; p3=p2+vnew/vnew(3)*(endplane-p1(3)); zplot=[zplot;p0(3),p1(3),p2(3),p3(3)]; xplot=[xplot;p0(1),p1(1),p2(1),p3(1)]; end;

Plot the complete raytrace
fig1=figure;plot(zplot',xplot','-');hold on;plot(zplot',-xplot','-'); plot([th,r-sqrt(r^2-((-1.1:0.001:1.1)*hmax).^2),th],... [-1.1,-1.1:.001:1.1,1.1]*hmax,'k-'); plot(th*[1,1],hmax*1.1*[-1,1],'k-'); axis([-1,5,-1.3,1.3]); hold off; xlabel('z, Axial Position');ylabel('x, Height');
Reverse the lens and trace again
zplot=[];xplot=[]; % arrays for plot variables pc=[0,0,th-r]'; % sphere center for h=(0:0.2:1)*hmax; % Loop on rays: h is height above vertex p0=[h,0,zstart]'; % p0 is the starting point v=[0,0,1]'; v=v/sqrt(v'*v); p1=p0+v/v(3)*(-p0(3)); % p1 is on the first (flat) surface nr=n; % relative index of refraction nor=[0,0,1]'; % Second surface vnew=v/nr+(sqrt(1-(1/nr)^2*(1-(v'*nor)^2))-v'*nor/nr)*nor; v=vnew; [s1,s2]=raysphere(p1,pc,v,r); p2=p1+s2*v; % p2 is on the second surface nor=+(p2-pc)/sqrt((p2-pc)'*(p2-pc)); % Unit normal nr=1/n; % relative index of refraction vnew=v/nr+(sqrt(1-(1/nr)^2*(1-(v'*nor)^2))-v'*nor/nr)*nor; p3=p2+vnew/vnew(3)*(endplane-p2(3)); zplot=[zplot;p0(3),p1(3),p2(3),p3(3)]; xplot=[xplot;p0(1),p1(1),p2(1),p3(1)]; end;

Plot the complete raytrace
fig2=figure;plot(zplot',xplot','-');hold on;plot(zplot',-xplot','-'); plot([0,th+r-sqrt(r^2+((-1.1:0.001:1.1)*hmax).^2),0],... [-1.1,-1.1:.001:1.1,1.1]*hmax,'k-'); plot(0*[1,1],hmax*1.1*[-1,1],'k-'); hold off; axis([-1,5,-1.3,1.3]); xlabel('z, Axial Position');ylabel('x, Height');