Erase vectors within a certain area on quiver plots

5 ビュー (過去 30 日間)
William McLemore
William McLemore 2022 年 2 月 9 日
回答済み: Simon Chan 2022 年 2 月 10 日
I am trying to make a quiver plot showing the flow of water around a hump who's center is located at the origin with a radius of 1cm. When I create the quiver plot, it creates vectors with bases inside this semicircular area. Is there any way to set parameters to remove these certain vectors from the plot?
Thanks.
Here is my code and the plot outputted:
clear;clc;
U = 5;
a = .01;
X = -.03:.003:.03;
Y = 0:.003:.03;
[x,y] = meshgrid(X,Y);
u = U + ((U*a^2)./((x.^2 + y.^2).^2)).*(y.^2 - x.^2);
v = ((U*a^2)./((x.^2 + y.^2).^2)).*(-2.*x.*y);
% if y < a^2 - x.^2
% u = 0; v = 0;
% end
theta = linspace(0, pi, 1000);
x_circ = a*cos(theta);
y_circ = a*sin(theta);
figure;
quiver(x, y, u, v, 4.5)
hold on
plot(x_circ,y_circ)
fill(x_circ,y_circ,"r")
axis equal
xlim([-.03 .03]);
ylim([0 .03]);
Here is the plot without the hump being filled. Obviously, these vectors should not exist since there is a solid object to cause the flow to move around it

採用された回答

Simon Chan
Simon Chan 2022 年 2 月 10 日
Find all points inside the semi-circle and set NaN to those points on vector u and v.
clear;clc;
U = 5;
a = .01;
X = -.03:.003:.03;
Y = 0:.003:.03;
[x,y] = meshgrid(X,Y);
u = U + ((U*a^2)./((x.^2 + y.^2).^2)).*(y.^2 - x.^2);
v = ((U*a^2)./((x.^2 + y.^2).^2)).*(-2.*x.*y);
% if y < a^2 - x.^2
% u = 0; v = 0;
% end
theta = linspace(0, pi, 1000);
x_circ = a*cos(theta);
y_circ = a*sin(theta);
y_circ(end) = 0; % Make sure the end point goes to 0
[in,~] = inpolygon(x,y,x_circ,y_circ); % Find points inside the semi-circile
u(in)=NaN; % Set value inside the semi-circle to NaN
v(in)=NaN;
figure;
quiver(x, y, u, v) % Auto scale
hold on
plot(x_circ,y_circ)
%fill(x_circ,y_circ,"r")
axis equal
xlim([-.03 .03]);
ylim([0 .03]);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by