Erase vectors within a certain area on quiver plots
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
William McLemore
le 9 Fév 2022
Réponse apportée : Simon Chan
le 10 Fév 2022
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

0 commentaires
Réponse acceptée
Simon Chan
le 10 Fév 2022
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Assembly dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
