Cartoons of different radiation polarizations

Matlab code 

% Cartoons of E- and B-fields propagating together along two wavelengths as

% a linearly polarized plane wave, or different light polarizations for the

% E-field only

 

clear; close all;

 

display('Choose one of the following: E & B together (E), lin horiz (H), lin vert (V),');

prompt = 'lin tilted (T), left circ (L), right circ (R)? ';

str = input(prompt,'s');

 

myBlue = [0.4 0.44 0.73];

 

str1 = 'EMpropagation_';

str3 = '.mp4';

fileName = [str1,str,str3]; % Name of file depends on polarization choice

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

vid.Quality = 100;

vid.FrameRate = 30;

open(vid);

figure('ToolBar','none');

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

set(gca,'linewidth',7);

set(gca, 'Projection','perspective');

 

lp = [0.4 0.4 0.7];

LL = 4*pi; % two wavelengths

wavex = 0:pi/90:LL;

wavey = 0.0*wavex;

 

for i = 0:pi/45:4*pi

    newplot;

    mArrow3([0 0 0],[4*pi 0 0],'color','k','stemWidth',0.064,'tipWidth’,...

         0.14,'facealpha',0.8);

    hold on;

    

    if (str == 'E') || (str == 'e')

        wavez = 4*sin((wavex) + (-i));

        % Horizontal E-field

        plot3(wavex,wavez,wavey,'color','red', 'LineWidth', 2.5); % E-field

        % Vertical B-field

        plot3(wavex,wavey,wavez,'color',myBlue, 'LineWidth', 2.5); % B-field

    elseif (str == 'H') || (str == 'h')

        % Horizontal polarization

        wavez = 4*sin((wavex) + (-i));

        plot3(wavex,wavez,wavey,'color','red', 'LineWidth', 2.5); % E-field

    elseif (str == 'V') || (str == 'v')

        % Vertical polarization

        wavez = 4*sin((wavex) + (-i));

        plot3(wavex,wavey,wavez,'color','red', 'LineWidth', 2.5); % E-field

    elseif (str == 'L') || (str == 'l')

        % Circular left polarization

        wavez = 4*sin((wavex) + (-i));

        wavey = 4*cos((wavex) + (-i));

        plot3(wavex,wavey,wavez,'color','red', 'LineWidth', 2.5); % E-field

    elseif (str == 'R') || (str == 'r')

        % Circular right polarization

        wavez = -4*sin((wavex) + (-i));

        wavey = -4*cos((wavex) + (-i));

        plot3(wavex,wavez,wavey,'color','red', 'LineWidth', 2.5); % E-field

    elseif (str == 'T') || (str == 't')

        % Tilted linear polarization

        wavey = 3*sin((wavex) + (-i));

        wavez = 3*sin((wavex) + (-i));

        plot3(wavex,wavey,wavez,'color','red', 'LineWidth', 2.5); % E-field

    end

    axis square;

    axis off;

    light('Position',lp,'Style','infinite');

    xlim([0 LL]);

    ylim([-LL/2 LL/2]);

    zlim([-LL/2 LL/2]);

    view(50,25);

    frame = getframe(gcf);

    writeVideo(vid,frame);

    hold off;

end

 

% Output the movie as an mpg file

close(vid);

% Movie of cartoon of forces acting on electron from EM wave

 

clear; close all;

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

vid.Quality = 100;

vid.FrameRate = 30;

open(vid);

 

myBlue = [0.4 0.44 0.73];

 

figure('units','pixels','position',[0 0 1920 1080],'ToolBar','none');

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

set(gca,'linewidth',7);

set(gca, 'Projection','perspective');

hold off;

lp1 = [0.4 -0.4 1.7];

lp2 = [0.4 -0.4 -0.7];

LL = 4*pi;

wavex = 0:pi/90:LL;

wavey = 0.0*wavex;

 

for i = 0:pi/90:LL

    newplot;

    r = 0.5;

    hold on;

    mArrow3([0 0 0],[LL 0 0],'color','black','stemWidth',0.04,'tipWidth',0.2,'facealpha',1);

    [x,y,z] = sphere(70); surf(x*r + pi,y*r,z*r,'FaceColor',[0.28 0.32 0.64],'EdgeColor','none');

    [x,y,z] = sphere(70); surf(x*r + 2.5*pi,y*r,z*r,'FaceColor',[0.28 0.32 0.64],'EdgeColor','none');

    % incoming EM-field

    wavez = 4*sin((wavex) + (-i));

    plot3(wavex,wavey,wavez,'color',myBlue, 'LineWidth', 2.5); % B-field

    plot3(wavex,wavez,wavey,'color','red', 'LineWidth', 2.5); % E-field

    mArrow3([pi 0 0],[pi -4*sin(i) 0],'color','red','stemWidth',0.1,'tipWidth',0.2,'facealpha',0.5); %

    mArrow3([2.5*pi 0 0],[2.5*pi -4*cos(i) 0],'color','red','stemWidth',0.1,'tipWidth',0.2,'facealpha',0.5); %

    mArrow3([pi 0 0],[pi 4*sin(i) 0],'color',myBlue,'stemWidth',0.1,'tipWidth',0.2,'facealpha',0.7); %

    mArrow3([2.5*pi 0 0],[2.5*pi 4*cos(i) 0],'color',myBlue,'stemWidth',0.1,'tipWidth',0.2,'facealpha',0.7); %

    

    axis square;

    axis off;

    light('Position',lp1,'Style','infinite');

    light('Position',lp2,'Style','infinite');

    xlim([0 LL]);

    ylim([-LL/2 LL/2]);

    zlim([-LL/2 LL/2]);

    view(50,25);

    % Store the frame

    frame = getframe(gcf);

    writeVideo(vid,frame);

    hold off;

end

hold off;

% Output the movie as an mpg file

close(vid);