2
votes

Recently, I've been using matlab to run a particle aggregation simulation, and I use its plotting itnerface to represent each particle. Thus, I've put together some code which adjusts the size of a marker such that it is equivalent to the actual particle's diameter - in relation to the window's aspect ratio and such. Well, this works very well if I'm dealing with a square domain; see below.

enter image description here

As you can see, the markers are sized such that particles will settle out on topof each other perfectly. Here's the plotting code for that image:

%%Initial Plot at time t = 0 Along with Scaling in the Y-Direction
figure;    h=scatter(Pos(1,:),Pos(2,:),6,jet(length(Pos(1,:))),'filled','MarkerEdgeColor','k','linewidth',1);
hold on
axis equal
axis ([0 dp 0 dp]*L*Scale)
currentunits = get(gca,'Units');
set(gca, 'Units', 'Points');
axpos = get(gca,'Position');
set(gca, 'Units', currentunits);
markerWidth = dp/diff(ylim)*axpos(4); % Calculate Marker width in points
set(h, 'SizeData', markerWidth^2)

Well, I added in periodic boundary conditions to my simulation, and this means that I can have 3X the window size shown above without much additional computation cost. So, I wanted to plot up a 3x1 domain (x is basically 3X longer than the y dimension of the domain). However, I'm having troubling sizing the particles appropriately such that they will be scaled properly in the y-direction yet also touch along the x-direction. I think I could do this using some kind of aspect ratio code, but I can't get it to work. Any ideas? Here's the code/result I came up with:

%Plot all of the data
figure;
h=scatter(Pos(1,:),Pos(2,:),6,jet(length(Pos(1,:))),'filled','MarkerEdgeColor','k','linewidth',1);
hold on
axis equal
axis ([0 3*dp 0 3*dp]*L*Scale)
currentunits = get(gca,'Units');
set(gca, 'Units', 'Points');
axpos = get(gca,'Position');
set(gca, 'Units', currentunits);
markerWidth = dp/diff(ylim)*axpos(4); % Calculate Marker width in points
set(h, 'SizeData', (markerWidth)^2)
axis ([0 3*dp 0 dp]*L*Scale)

It produces the following result,which is obviously incorrect :(... enter image description here

1
Oh! A high-quality question. Haven't seen one in a while on that tag. - Cape Code
I giggled I admit... - bla
Thought about drawing the circles by yourself instead of using scatter? I think it's more appropriate in your case. - Robert Seifert

1 Answers

2
votes

You could use something like

%cirlce def
circx = sin(linspace(0,2*pi,100));
circy = cos(linspace(0,2*pi,100));

%example data
[mgx mgy] = meshgrid(5:5:100, 5:5:100);
x = reshape(mgx,[],1); %circles centers x
y = reshape(mgy,[],1); %circles centers x
r = 2.5*rand(400,1);   %radii
c = 250*rand(400,1);   %colors

% draw
figure
hold on
for i=1:numel(x)
  fill(r(i)*circx+x(i), r(i)*circy+y(i), c(i))
end

so that all all geometric data is fixed into coordinate axes space. Example output is:

Example result