clear all
close all

% Incorrect empty plot with small plot limits and 'hold all'
figure(1);
hold all
axis equal

c = 0.05;

angles = -pi/4:pi/24:pi/4;
for I=1:length(angles)
    theta = angles(I); % iterate angle theta
    X = [0 c  c-c*sin(theta) -c*sin(theta) 0]'; % plot resulting parallelogram
    Y = [0 0  c*cos(theta) c*cos(theta) 0]';
    
    
    plot(X,Y);
    xlim([-c 2*c]);
    ylim([-c 2*c]);  
end

% Correct plot with larger plot limits and 'hold all'
figure(2);
hold all
axis equal

c = 0.5;

angles = -pi/4:pi/24:pi/4;
for I=1:length(angles)
    theta = angles(I); % iterate angle theta
    X = [0 c  c-c*sin(theta) -c*sin(theta) 0]'; % plot resulting parallelogram
    Y = [0 0  c*cos(theta) c*cos(theta) 0]';
    
    
    plot(X,Y);
    xlim([-c 2*c]);
    ylim([-c 2*c]);  
end

% Correct behavior with small plot limits and no 'hold all'
figure(3);
axis equal

c = 0.05;

angles = -pi/4:pi/24:pi/4;
for I=1:length(angles)
    theta = angles(I); % iterate angle theta
    X = [0 c  c-c*sin(theta) -c*sin(theta) 0]'; % plot resulting parallelogram
    Y = [0 0  c*cos(theta) c*cos(theta) 0]';
    
    
    plot(X,Y);
    xlim([-c 2*c]);
    ylim([-c 2*c]);  
end
