McGill University
School of Computer Science

Computer Science COMP 199 (Winter term)
Excursions in Computing Science

%MATLABpak02: unpolarizedQuiver, polarizedQuiver, rotateQuiver

% unpolarizedQuiver.m	THM	060714
% quiver(Xb,Yb,c,s,0,'.')
% Edges with random orientations, theta: Xc, Yc centres on regular grid;
% Xb, Yb are the starting coordinates; c, s are the extents
[Xc,Yc] = meshgrid(-10:2:10);
theta = pi*rand(11);
c = cos(theta);
s = sin(theta);
Xb = Xc - c/2;
Yb = Yc - s/2;
quiver(Xb,Yb,c,s,0,'r.')

% polarizedQuiver.m	THM	060714
% quiver(Xb,Yh,c,sh,0,'g.')
% Show horizontal projections (Yh, sh=0) of light beams from unpolarizedQuiver.m
[Xc,Yc] = meshgrid(-10:2:10);
theta = pi*rand(11);
c = cos(theta);
Xb = Xc - c/2;
Yh = Yc;
sh = zeros(11);
quiver(Xb,Yh,c,sh,0,'g.')
axis([-15 15 -15 15])		% override MATLAB default, to match unpolarized

% rotateQuiver.m	THM	060703
% use quiver(X,Y,U,V) to display rotation from [X;Y] to [U;V]
clear U, clear V	% permits running a small mesh after a big one
[X,Y] = meshgrid(-10:1:10);
theta = pi/20;
c = cos(theta);
s = sin(theta);
A = [c,-s;s,c];
for j1 = -10:1:10
	j = j1 + 11;
	for k1 = -10:1:10
		k = k1 + 11;
		XY = [X(j,k);Y(j,k)];
		UV = A*XY;
		U(j,k) = UV(1) - XY(1);	% quiver plots XY + UV
		V(j,k) = UV(2) - XY(2);
	end;
end;
quiver(X,Y,U,V,0)	% scale=0 to force no autoscaling