clc 
close all
clear all

%% forward wind directions
%anp=[0 72 144 216 288];
%anp=[0 65 147 210 288];
anp=[0 75 140 210 300];
%anp=[0 140 300 75 210];
%anp=[0 72 144 216 288];
%anp=[0 110 200 270];
%anp=[0 60 150 300];
%anp=[0 60 150 240];
%anp=[0 50 140 210];
an=2*pi*anp/360;
%an1=an+pi/5;

%%% for each wind direction, all possible angles of arm propagation

for i=1:size(anp,2)
alp(:,i)=linspace(0,2*pi,1000)'+an(i);
end

%%%% abs(sin(alp)): dune slope experienced by the wind 
%%%% cos(alp): sand flux oriented toward the arm tip
%%%% we sum on each wind and search for the max flux

fl_para=sum(abs(sin(alp)).*cos(alp),2);
fl_para1=sum(abs(sin(alp)).*sin(alp),2);
fl1=sum(sin(an),2);
fl2=sum(cos(an),2);

figure
plot(linspace(0,2*pi,1000),fl_para,'b','linewidth',3)
hold on
plot(linspace(0,2*pi,1000),fl_para1,'r','linewidth',3)
str={'0';'p/2';'p';'3p/2';'2p'};
set(gca,'xtick',[0:pi/2:2*pi],'xticklabel',str,'fontname','symbol','fontsize',18,'plotboxaspectratio',[1 1 1])
%set(gca,'xtick',[0:pi/2:2*pi],'xticklabel',{0,\pi/2,'pi','3\pi/2','2\pi'})
%title('5 wind directions','fontsize',20,'fontname','helvetica')
xlabel('Angle \alpha [rad]','fontsize',20,'fontname','helvetica')
ylabel('Flux [dimensionless]','fontsize',20,'fontname','helvetica')
axis([0 2*pi -0.8 0.8])

%%% cumulative resultants of the wind flows

op=[ 0 0
cumsum(cos(an))' cumsum(sin(an))'];
figure;plot(op(:,1),op(:,2))

%text(2*pi/10-0.2,0.42,'p/5','fontsize',20,'fontname','symbol')
%text(2*pi/10+2*pi/5-0.2,0.42,'3p/5','fontsize',20,'fontname','symbol')
%text(2*pi/10+4*pi/5-0.1,0.42,'p','fontsize',20,'fontname','symbol')
%text(2*pi/10+6*pi/5-0.2,0.42,'7p/5','fontsize',20,'fontname','symbol')
%text(2*pi/10+8*pi/5-0.2,0.42,'9p/5','fontsize',20,'fontname','symbol')

% 
%print -depsc flux_theorie.eps
