close all
clear all


XVel = 10/28;  %Max Carriage Speed
YVelMax = (3.33-.011)/28; % Max Crane Speed;
YVel = -YVelMax:YVelMax/100:YVelMax; 
theta = atan2(YVel,XVel)*180/pi;
V = (XVel^2+YVel.^2).^.5;

for i = 1:length(theta);
  alpha(i) = ActualWingAngle(theta(i),V(i));
end


figure
ph1 = plot(theta,alpha,'Color','r')
xlabel('theta (deg)');
ylabel('Expected Wing Angle (deg)');
legend('Carriage at Full Speed');
ax1 = gca; % current axes
%ax1.XColor = 'r';
%ax1.YColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax1.XLim = [min(theta) max(theta)];
ax2 = axes('Position',ax1_pos,...
    'XAxisLocation','top',...
    'YAxisLocation','right',...
    'Color','none');
ph2 = plot(ax2,YVel,alpha,'Parent',ax2,'Color','k')
ax2.XAxisLocation = 'top';
ax2.XLim = [min(YVel) max(YVel)];
title('Carriage at Full Speed');
grid on;



for n = 1:2
    
XVel = 10/28;  %Max Carriage Speed
XVel = [0:XVel/50:XVel];
if(n == 1)
  YVel = (3.33-.011)/28; % Crane Speed (positive equals up);
else
  YVel = -(3.33-.011)/28; % Crane Speed (negative equals down); 
end
theta = atan2(YVel,XVel)*180/pi;
V = (XVel.^2+YVel^2).^.5;

clear alpha;
for i = 1:length(theta);
  alpha(i) = ActualWingAngle(theta(i),V(i));
end

figure
ah(1) = subplot(2,1,1);
plot(theta,alpha);
xlabel('theta (deg)');
ylabel('Expected Wing Angle (deg)');
ah(2) = subplot(2,1,2);
plot(XVel,alpha);
xlabel('Carriage Speed (m/s)');
ylabel('Expected Wing Angle (deg)');

% 
% figure
% ph1 = plot(theta,alpha,'Color','r')
% xlabel('theta (deg)');
% ylabel('Expected Wing Angle (deg)');
% ax1 = gca; % current axes
% %ax1.XColor = 'r';
% %ax1.YColor = 'r';
% ax1_pos = ax1.Position; % position of first axes
% %ax1.XLim = [min(theta) max(theta)];
% ax2 = axes('Position',ax1_pos,...
%     'XAxisLocation','top',...
%     'YAxisLocation','right',...
%     'Color','none');
% ph2 = plot(ax2,XVel,alpha,'Parent',ax2,'Color','k')
% ax2.XAxisLocation = 'top';
% %ax2.XLim = [min(XVel) max(XVel)];
% if(n == 1)
%   title('Crane at Full Speed Down');
% else
%   title('Crane at Full Speed Up'); 
% end    
% grid on;

end
