MATLAB Answers

Boundary line for contour

2 views (last 30 days)
Pooyan Jafari
Pooyan Jafari on 29 Nov 2020
Edited: Star Strider on 1 Dec 2020
Hello,
I want to draw a boundary line for my contour
you can see my contour (without bondary) and a contour with boundary (desired)
you can see my contour (without bondary)
here is my code:
clc,clear,close all;
% syms z y ;
B = 10;
H = 5;
C = 10;
L1 = 1;
Ri = B/2 + L1;
Rf = C + B/2 + L1;
y = linspace(-25,0,1000);
z = linspace(0,28,1000);
[Z,Y] = meshgrid(z,y);
r1 = sqrt((Y.^2)+(Z.^2));
r = abs(sqrt((Y.^2)+(Z.^2)) - Rf);
beta = asin( Z ./ sqrt((Y.^2)+(Z.^2)) );
beta(1000,1) = 0;
Rbeta = Ri + (2.*beta.*(Rf-Ri)./pi);
Rt0 = B/2+L1;
Rmaxtb = (Rt0.*Rbeta)./Ri;
Vmbeta = (2*(pi^2)*((B+(2*L1))^2)) ./ ((((2*L1*pi)+(pi*B)+(4.*beta.*C)).^2));
% Calculate the distance for condition
Rt00 = (B/2-L1);
Rmaxtbb = (Rt00.*Rbeta)./Ri;
% End
for i = 1:1:1000
for j = 1:1:1000
if r(i,j)>Rbeta(i,j) | r1(i,j)>(Rf+Rmaxtbb(i,j))
Vbeta(i,j)=0;
else
Vbeta(i,j) = Vmbeta(i,j) * (1 - ((r(i,j)^2) / (Rmaxtb(i,j)^2)));
end
end
end
ZZ = Z./B;
YY = Y./B;
contourf(ZZ,YY,Vbeta,100,'edgecolor','none')
colormap( flipud(gray(256)) )
colorbar
xlabel('z/D')
ylabel('y/D')
any help is appreciated

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 29 Nov 2020
Sometimes, a bit of absolute creativity (‘thinking outside the contour) is necessary.
I first did a meshc plot of your matrices to see what the ‘Vbeta’ matrix looked like in 3D. It has a sllight elevation with steep transitions at the edges. That led to experiments using the gradient function to calculate numerical derivatives of the ‘Vbeta’ matrix, and that led to this result (with code previous to this not copied here):
ZZ = Z./B;
YY = Y./B;
contourf(ZZ,YY,Vbeta,100,'edgecolor','none')
colormap( flipud(gray(256)) )
colorbar
xlabel('z/D')
ylabel('y/D')
[~,dY] = gradient(Vbeta);
hold on
contour(ZZ.*(dY~=0),YY.*(dY~=0),ones(size(dY)).*(dY~=0), [0 1], '--k')
hold off
producing this plot:
I have no idea how robust this approach would be to similar plots, however it appears to work here. It uses a second contour call and logical indexing (of a sort) to ptroduce the necessary contours.

  3 Comments

Pooyan Jafari
Pooyan Jafari on 30 Nov 2020
Thank you
it is working great!!
would you please help me with this one too!?
clc,clear,close all;
B = 10;
H = 20;
C = 10;
L1 = 5;
Ri = B/2 + L1;
Rf = C + B/2 + L1;
y = linspace(-25,0,1000);
z = linspace(0,25,1000);
[Z,Y] = meshgrid(z,y);
r1 = sqrt((Y.^2)+(Z.^2));
r = abs(sqrt((Y.^2)+(Z.^2)) - Rf);
beta = asin( Z ./ sqrt((Y.^2)+(Z.^2)) );
beta(1000,1) = 0;
Rbeta = Ri + (2.*beta.*(Rf-Ri)./pi);
Rt0 = B/2+L1;
Rmaxtb = (Rt0.*Rbeta)./Ri;
% Calculate the distance for condition
Rt00 = (B/2-L1);
Rmaxtbb = (Rt00.*Rbeta)./Ri;
% End
for i = 1:1:1000
for j = 1:1:1000
cond(i,j) = Rf-Rbeta(i,j);
if (r1(i,j)<=cond(i,j)) | (r1(i,j)>(Rf+Rmaxtbb(i,j)))
Vr(i,j)=0;
else
if r1(i,j)<Rf
Vr(i,j) = -(399200400000000000*r(i,j)*pi^2*(2000*beta(i,j) + 999*pi - 100*pi*r(i,j))*(2000*beta(i,j) + 999*pi + 100*pi*r(i,j)))/((100*r(i,j) - 1999)*(2000*beta(i,j) + 999*pi)^5*(250000*cot(8359544324750471/18014398509481984) + 998001*tan(8359544324750471/18014398509481984) - 250000*cot(3541622469636805/2251799813685248) - tan(3541622469636805/2251799813685248)));
else
Vr(i,j) = -(399200400000000000*r(i,j)*pi^2*(2000*beta(i,j) + 999*pi - 99900*pi*r(i,j)*-1)*(2000*beta(i,j) + 999*pi + 99900*pi*r(i,j)*-1))/((100*r(i,j)*(-1) - 1999)*(2000*beta(i,j) + 999*pi)^5*(250000*cot(8359544324750471/18014398509481984) + 998001*tan(8359544324750471/18014398509481984) - 250000*cot(3541622469636805/2251799813685248) - tan(3541622469636805/2251799813685248)));
end
end
end
end
ZZ = Z./B;
YY = Y./B;
contourf(ZZ,YY,Vr,100,'edgecolor','none')
colormap( flipud(gray(256)) )
colorbar
xlabel('z/D')
ylabel('y/D')
the difference is that here Vbeta is replaced by Vr.
I used your approach adn it didn't work for this one. Actually it draws the boundary for the contour, but the color of the contour is fading!! you can see the picture of the original contour and the contour with boundary with your approach
Star Strider
Star Strider on 1 Dec 2020
My pleasure!
Experiment with the caxis function to create the color axis range (herre the intensity of the gray colormap) that you want.
Example —
ZZ = Z./B;
YY = Y./B;
contourf(ZZ,YY,Vr,100,'edgecolor','none')
colormap( flipud(gray(256)) )
lim = caxis;
caxis(lim.*[1.50 0.50]) % Limits The Color Axis Range
colorbar
xlabel('z/D')
ylabel('y/D')
[~,dY] = gradient(Vr);
hold on
contour(ZZ.*(dY~=0),YY.*(dY~=0),ones(size(dY)).*(dY~=0), [0 1], '--k')
hold off
Here, I multiplied the lower limit by 1.5 and the upper limit by 0.5 to decrease the range. Experiment with them to get the result you want.
EDIT — (1 Dec 2020 at 00:32)
Added new plot image —
.
.
Star Strider
Star Strider on 1 Dec 2020
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (1)

VBBV
VBBV on 29 Nov 2020
Edited: VBBV on 29 Nov 2020
%true
contourf(ZZ,YY,Vbeta,'--')
colormap( flipud(gray(256)) )
colorbar
xlabel('z/D')
ylabel('y/D')

  2 Comments

VBBV
VBBV on 29 Nov 2020
%tr%true
[M c] = contourf(ZZ,YY,Vbeta)
c.LineStyle = '--';
c.LineWidth = 0.5
Pooyan Jafari
Pooyan Jafari on 29 Nov 2020
thank you for your answer
I changed my code as below and it didn't work
ZZ = Z./B;
YY = Y./B;
[M c]=contourf(ZZ,YY,Vbeta,100,'edgecolor','none')
c.LineStyle = '--';
c.LineWidth = 0.5;
colormap( flipud(gray(256)) )
colorbar
xlabel('z/D')
ylabel('y/D')

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!