How to fill the area between two curves?
I want to shade the portion between red curve and green curve, but im not getting the proper way of doing it. Can anyone help me with your idea? I have attached a code and the figure for your reference.
Lx = 150;
Ly = 150;
T0 =0;
T1 = pi/4;
T=3.175;
N=8;
W=N*T;
X0=Lx/2;
Y0=0;
W_nominal=W/2;
for a=1:2
r=rem(a,2);
if r==0
xp=0; xn=0; i=1;
while (xp>=0 && xp<=Lx/2)
XPaxisl(i)=xp+(i-1)*Lx/1200; xp=XPaxisl(i);
XNaxisl(i)=xn+(i-1)*(-Lx)/1200; xn=XNaxisl(i);
Th(i)=T0+2*((T1-T0)*(XPaxisl(i)))/Lx;
TH(i)= T0+2*((T0-T1)*(XNaxisl(i)))/Lx;
Wp(i)=W_nominal/cos(Th(i));
WP(i)=W_nominal/cos(TH(i));
ypl(i)=Wp(i)+(Lx/(2*(T0-T1))*((-log(cos(T0)))+log(cos(T0+((2*(T1-T0)*XPaxisl(i))/Lx)))));
ynl(i)=WP(i)+(Lx/(2*(T1-T0))*((-log(cos(T0)))+log(cos(T0+((2*(T0-T1)*XNaxisl(i))/Lx)))));
i=i+1;
end
%figure(1)
plot(XPaxisl,ypl, '-g')
hold on
plot(XNaxisl,ynl, '-g')
hold on
x1 = XPaxisl;
y1 = ypl;
x2 = XNaxisl;
y2 = ynl;
end
%% shifting
r=rem(a,2);
if r==0
xp=0; xn=0; i=1; y=0; yn=0;
while (xp>=0 && xp<=Lx/2) && (y<=Ly/2)
XPaxiss1(i)=xp+(i-1)*Lx/1200; xp=XPaxiss1(i);
yps1(i) =(a*W_nominal)+Lx/(2*(T0-T1))*((-log(cos(T0)))+log(cos(T0+((2*(T1-T0)*XPaxiss1(i))/Lx))));
i=i+1;
end
else
xp=0; xn=0; i=1; y=0; yn=0;
while (xp>=0 && xp<=Lx/2) && (y<=Ly/2)
XPaxiss1(i)=xp+(i-1)*Lx/1200; xp=XPaxiss1(i);
XNaxiss1(i)=xn+(i-1)*(-Lx)/1200; xn=XNaxiss1(i);
yps1(i) =(a*W_nominal)+Lx/(2*(T0-T1))*((-log(cos(T0)))+log(cos(T0+((2*(T1-T0)*XPaxiss1(i))/Lx))));
yns1(i)= (a*W_nominal)+Lx/(2*(T1-T0))*((-log(cos(T0)))+log(cos(T0+((2*(T0-T1)*XNaxiss1(i))/Lx))));
i=i+1;
end
plot(XPaxiss1,yps1, '-r')
hold on
plot(XNaxiss1,yns1, '-r')
xlim([-Lx/2 Lx/2])
ylim([-Ly/2 Ly/2])
x3 = XPaxiss1;
y3 = yps1;
x4 = XNaxiss1;
y4 = yns1;
end
end
x2=x2(end:-1:1);
y2=y2(end:-1:1);
x4=x4(end:-1:1);
y4=y4(end:-1:1);
X1 = horzcat(x2(1:end-1),x1)
Y1 = horzcat(y2(1:end-1),y1);
X2 = horzcat(x4(1:end-1),x3)
Y2 = horzcat(y4(1:end-1),y3);
%figure(2)
%plot(X1,Y1)
%hold on
%plot(X2,Y2)
%xlim([-Lx/2 Lx/2])
%ylim([-Ly/2 Ly/2])
Area = trapz(X1,abs(Y1-Y2))
Accepted Answer
More Answers (1)
0 votes
Categories
Find more on Time Series Events in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!