Ray tracing of focussing using ellipses and parabolas

Matlab codes

% Program to plot reflection of rays originating at one of the foci of an

% ellipse. The ellipse ratio a/b is an input parameter

clear; close all;

prompt = 'Ratio of major to minor axes [>1; default 5]: ';

aob = input(prompt);

if isempty(aob)

aob = 5;

end

aaxis = 1.0; % semimajor axis

baxis = aaxis/aob;  % semiminor axis

str1 = 'ellipseFocussing_a2b_';

str2 = num2str(aob);

str3 = '.mp4';

strTot = [str1,str2,str3];

vid = VideoWriter(strTot,'MPEG-4');

vid.FrameRate = 60;

vid.Quality = 100;

open(vid);

figure('ToolBar','none');

set(0,'defaultfigurecolor',[1 1 1]);

theta = (-pi:pi/200:pi)'; % causes the chords to make one full period forwards/backwards

xcoord = (cos(theta)).*aaxis;

ycoord = baxis.*(1 - xcoord.^2./aaxis^2).^0.5;

foci = (aaxis^2 - baxis^2)^0.5;

% Plot

for i = 1:size(xcoord,1)

hold off;

plot(xcoord,ycoord,'color',[0,0,0], 'LineWidth', 2.0); % top half of ellipse

axis([-aaxis-0.1 aaxis+0.1 -aaxis-0.1 aaxis+0.1]);

axis square % square plot

axis equal

axis off

hold on;

plot(xcoord,-ycoord,'color',[0,0,0], 'LineWidth', 2.0); % bottom half of ellipse

xchord = [-foci xcoord(i) foci]; % x-coordinates of ray path between foci

ychord = [0 ycoord(i) 0]; % y-coordinates of ray path between foci

plot(xchord,ychord, 'color',[1 0 0], 'Linewidth', 2.0); % reflection off upper half

plot(xchord,-ychord, 'color',[1 0 0], 'Linewidth', 2.0); % reflection off lower half

% Store the frame

frame = getframe(gcf);

writeVideo(vid,frame);

end

hold off;

% Output the movie as an mpg file

close(vid);

% Program to plot reflection of incident parallel rays on a parabolic

% surface coming to a focus at a point

clear; close all;

aconst = 5.0; % constant in x = ay^2

nR = 0.99;

vid = VideoWriter('parabolaFocussingTransmission.mp4','MPEG-4');

vid.FrameRate = 30;

vid.Quality = 100;

open(vid);

figure('ToolBar','none');

set(0,'defaultfigurecolor',[1 1 1]);

ycoord = (-0.2:0.00999999:0.2)'; % range of y-values of incoming horizontal beam

xcoord = aconst.*ycoord.^2; % x-value for a given y-value on surface of parabola

% Max x-value

thetaP = acos(nR*cos(theta));

delta = thetaP - theta;

xmax = xcoord(size(ycoord,1)) + ycoord(size(ycoord,1))/tan(delta);

for i = 1:size(ycoord,1)

hold off;

thetaP = acos(nR*cos(theta));

delta = thetaP - theta;

xf = xcoord(i) + abs(ycoord(i))/tan(delta);

fill([xcoord' -0.5 -0.5 min(xcoord)],[ycoord' 0.2 -0.2 -0.2],[0.5 0.5 0.5],'LineStyle','none');

hold on

plot(xcoord,ycoord,'color',[0,0,0], 'LineWidth', 2.0); % plot parabola

axis([-0.7 xmax -(xmax/2-0.05)/20 (xmax/2+0.05)/20]);

axis square % square plot

axis off

hold on;

xchord = [-0.7 xcoord(i) xf]; % x-coordinates of ray path between foci

ychord = [ycoord(i) ycoord(i) 0]; % y-coordinates of ray path between foci

plot(xchord,ychord, 'color',[1 0 0], 'Linewidth', 2.0); % reflection off upper half

plot(xchord,-ychord, 'color',[1 0 0], 'Linewidth', 2.0); % reflection off lower half

str1 = 'n = ';

str2 = num2str(nR,'% 4.3f');

strTot = [str1,str2];

hText = text(xmax*.8, -0.16, strTot, 'FontSize',14);

hText = text(xmax*.8, -0.195, 'x = 5y^2', 'FontSize',14);

% Store the frame

frame = getframe(gcf);

writeVideo(vid,frame);

end

hold off;

% Output the movie as an mpg file

close(vid);

% Program plotting parallel rays focussed by refraction as they pass

% through a plano-parabolic lens. The x- and y-dimensions are not equal in

% order to enhance the refraction angles

clear; close all;

aconst = 1.6; % constant in x = ay^2

vid = VideoWriter('parabolaFocussingReflection.mp4','MPEG-4');

vid.FrameRate = 30;

vid.Quality = 100;

open(vid);

figure('ToolBar','none');

set(0,'defaultfigurecolor',[1 1 1]);

ycoord = (-1:0.0099999999:1)'; % range of y-values of incoming horizontal beam

xcoord = aconst.*ycoord.^2; % x-value for a given y-value on surface of parabola

xmax = xcoord(size(ycoord,1)) + 1;

for i = 10:size(ycoord,1)-10

hold off;

ldist = abs(ycoord(i))/tan(2*theta);

xf = xcoord(i) - ldist;

plot(xcoord,ycoord,'color',[0,0,0], 'LineWidth', 2.0); % plot parabola

axis([-0.1 xmax -xmax/2-0.05 xmax/2+0.05]);

axis square % square plot

axis equal

axis off

hold on;

xchord = [xf xcoord(i) xmax]; % x-coordinates of ray path between foci

ychord = [0 ycoord(i) ycoord(i)]; % y-coordinates of ray path between foci

plot(xchord,ychord, 'color',[1 0 0], 'Linewidth', 2.0); % reflection off upper half

plot(xchord,-ychord, 'color',[1 0 0], 'Linewidth', 2.0); % reflection off lower half

frame = getframe(gcf);

writeVideo(vid,frame);

end

hold off;

% Output the movie as an mpg file

close(vid);