MATLAB Answers

How can I delete a circle from my 2D Meshgrid domain?

10 views (last 30 days)
Joseph Vannel Fotso Fogang
Answered: Aditya Patil on 21 Sep 2020
With the following code, I want to plot the velocity field but the points (x,y) falling within the filled circle have really high values with respect to the normal ones which are outside.
I want to delete (not consider) from my domain, points (x,y) falling inside the circle. This way, I will be able to scale my velocities accordingly.
U0=1; %Uniform flow velocity
r0=1; %radius of the imaginary sphere
k=0.5*U0*r0^3 %strength of the dipole
c=k*4*pi;
x = -2.05:.1:2.05;
y = -2.05:.1:2.05;
[X,Y] = meshgrid(x,y);
t=atan2(Y,X);
r=sqrt(X.^2+Y.^2);
%Stream function
psi = 0.5*U0*Y.^2.*(1-r0^3./(X.^2+Y.^2).^1.5);
%Velocity potential
phi = U0*X.*(1+0.5*r0^3./((X.^2+Y.^2).^1.5));
% Velocity in polar coordinates
vr = U0.*cos(t).*(1-r0^3./(r.^3));
vt = -U0.*sin(t).*(1+.5*r0^3./(r.^3));
% Velocity in cartesian coordinates
vx = U0 + c./(4*pi*(X.^2 + Y.^2).^(3/2)) - 3*c*X.^2./(4*pi*(X.^2 + Y.^2).^(5/2));
vy = -(3*c*X.*Y)./(4*pi*(X.^2 + Y.^2).^(5/2));
%Pressure coefficient on the sphere surface
theta=0:pi/100:2*pi;
Cp=1-9/4.*sin(theta).^2;
%Plots streamlines
contour(X,Y,psi,20,'k')
xlabel('x'); ylabel('y')
hold on
grid on
line(xlim, [0,0], 'Color', 'r', 'LineWidth', 1); % Draws a line for X axis
line([0,0], ylim,'Color', 'r', 'LineWidth', 1); % Draws a line for Y axis
axis equal
title("Potential flow around a sphere")
%Plots equipotential lines
contour(X,Y,phi,400,'k')
%Plots velocities
factor=.001
quiver(X,Y,vx*factor,vy*factor,'g','AutoScale','off');
filling(r0,'w');

  1 Comment

Joseph Vannel Fotso Fogang
It plots the following without the manually added filled circle. All the points inside the circle are not physically meaningful, they simply need not to be plotted. I don't know how to do so.

Sign in to comment.

Answers (1)

Aditya Patil
Aditya Patil on 21 Sep 2020
You can use boolean matrix to select unwanted variables, and set them to zero or nan.
For example, in this case, you can find those X,Y pairs which lie inside unit circle as follows,
flag = [abs(sqrt(X.^2 + Y.^2)) < 1] % We are calculating distance from origin
Then use this flag to remove unwanted data from variables to be plotted, as follows
psi(flag) = nan % or zero, as appropriate
Then plot the data as usual.

  0 Comments

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!