Download matlab code

% Movie of Lorentz force, current, and B-field

 

clear; close all;

 

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

vid.Quality = 100;

vid.FrameRate = 30;

open(vid);

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

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

set(gca,'linewidth',7);

 

myBlue = [0.4 0.44 0.73];

 

hold off;

lp = [0.4 -0.4 0.7];

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

for i = 0:pi/180:2*pi

    newplot;

    mArrow3([0 0 0],[1 0 0],'color',myBlue,'stemWidth',0.016,...

        'tipWidth',0.04,'facealpha',0.8); % conv current

    mArrow3([0 0 0],[-1 0 0],'color',myBlue,'stemWidth',0.016,...

        'tipWidth',0.04,'facealpha',0.8); % electron flow

    mArrow3([0 0 0],[-sin(i) 0 -cos(i)],'color',[0.9 0.8 0],'stemWidth',...

        0.016,'tipWidth',0.04,'facealpha',0.8); % B-field

    mArrow3([0 0 0],[0 cos(i) 0],'color','red','stemWidth',0.016,...

        'tipWidth',0.04,'facealpha',1); % Lorentz force

    r = 0.08;

    hold on;

    [x,y,z] = sphere(70); surf(x*r,y*r,z*r,'FaceColor',myBlue,'EdgeColor','none');

    axis square;

    axis off;

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

    LL = 1;

    xlim([-LL LL]);

    ylim([-LL LL]);

    zlim([-LL LL]);

    view(-35,31);

    hold off;

    % Store the frame

    frame = getframe(gcf);

    writeVideo(vid,frame);

    hold off;

end

hold off;

% Output the movie as an mpg file

close(vid);

The Lorentz force

Matlab code