2

I've been playing with animating flows in MATLAB recently.

Though I managed to get the following working fine, I was wondering if there was a way to constantly seed new particles from the starting locations, i.e. When a particle leaves the view, a new one can appear in a starting location.

% Node points
x = 0:100;
y = 0:100;

% Grid of all points
[X,Y] = meshgrid(x, y);

% Coefficients for Velocity field
K = 10;
C = 10;

% Velocity vector calcs (wavy example flow)
Vx = K + C * sin(x);
Vy = (K/2) + (C/2) * cos(y);

% Grid of velocity vectors
[VX,VY] = meshgrid(Vx, Vy);

% Plots the velocity streamslice
streamslice(X, Y, VX, VY);

% Starting points for the particles
Sx = 0;
Sy = 0:20:100;

% Grid of starting points
[SX,SY] = meshgrid(Sx, Sy);

% stream2 computes 2D streamline data
vertices = stream2(X, Y, VX ,VY, SX, SY);

% Interpolates stream line velocities
iverts = interpstreamspeed(X, Y, VX, VY, vertices, 0.05);

% Adds animated stream particles
streamparticles(iverts,1,'Animate',100,...
    'ParticleAlignment','on',...
    'MarkerFaceColor','red',...
    'Marker','o');

Edit: Follow up question: If I wanted to plot transient velocities which change with time, would this simply be plotted in a loop, or would this kind of animation not work, as the streamparticles function wouldn't know where the particle was the previous timestep?

Thanks

Laurengineer
  • 737
  • 1
  • 9
  • 26

1 Answers1

0

In order to continuously seed new particles from the start position, try to increase the first number after 'iverts' in the streamparticles function:

E.g. %Adds animated stream particles streamparticles(iverts,5,'Animate',100,... 'ParticleAlignment','on',... 'MarkerFaceColor','red',... 'Marker','o');