Erase vectors within a certain area on quiver plots

조회 수: 1 (최근 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 CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by