% Transverse Electromagnetic Wave % Greg Galloway % % This file demonstrates visually the fields involved with % a transverse electromagnetic wave. clc;clear;clf %Values repetitions = 5; %Number of times to repeat x_range = 14; x_start = -7; tsteps = .01; time = 0:tsteps:x_range; step_cnt = floor(x_range/tsteps); %Total number of steps bars = 40; %delay between bars magnitude = 6; %Magnitude of waves x_modulo = 14; %Loop size % x_start = -x_modulo/2; %X start location filler = zeros(size(mod(time,x_modulo))); %Zero vector filler % BALL COLORS colr = [1 0 0;0 1 0;0 0 1]; % DIMENSIONS OF BOX: Width:X, Length:Y, Height:Z width = 15;height = 15;length=15; center=[0,0,0]; % Graph dimensions dimensions = [-width/2+center(1) width/2+center(1) -length/2+center(2) ... length/2+center(2) -height/2+center(3) height/2+center(3)]; for j = 1:1:3 %This initializes the 'ball' values handle(j) = line(0,0,0,'linestyle','none','marker','o','markersize',10,'erasemode','normal','markeredgecolor','k','markerfacecolor',colr(j,:)); end handle(4) = line([0,0],[0,0],[0,0]); %This initializes the paths the balls will travel along pos_1 = [time+x_start; filler; filler]; %Axis of propogation pos_2 = [time+x_start; magnitude.*sin(time); filler]; pos_3 = [time+x_start; filler; magnitude.*sin(time)]; pos = cat(3,pos_1,pos_2,pos_3); %This begins the plotting portion axis(dimensions); title('Transverse Electromagnetic Wave Demonstration') for x = 1:1:repetitions; for i = 1:1:step_cnt; for k = 1:1:3 set(handle(k),'xdata',pos(1,i,k),'ydata',pos(2,i,k),'zdata',pos(3,i,k),'erasemode','normal'); end for k = 2:1:3 if floor(i/bars) == ceil(i/bars) handle(4)=line([pos(1,i,k),pos(1,i,k)],[0,pos(2,i,k)],[0,pos(3,i,k)],'color',colr(k,:)); end end if pos(1,i,2) ==x_start clf; for j = 1:1:3 %This redisplays the balls handle(j) = line(0,0,0,'linestyle','none','marker','o','markersize',10,'erasemode','normal','markeredgecolor','k','markerfacecolor',colr(j,:)); axis(dimensions); title('Transverse Electromagnetic Wave Demonstration') end end drawnow; end end