Creating Spherical Particle Agglomerates in Matlab in 2D or 3D

4 visualizzazioni (ultimi 30 giorni)
Hello,
I have a small question and I would like to know any tips or hints or a small code patch on how to proceed with it.
I have to create spherical particle agglomerates in matlab of different sizes all joined together. The number of particles are arbitary, given by me, it could be 5 ,10 ,50, 100 or 500 etc. The particles would be stationary. I have the diameters of the spherical particles and their <x,y> coordinates. At first I have to create particles in 2D and than in 3D. The output I would need after creating the particles would be their <x,y> coordinates again and their visualization so I can compare if they are created correctly or not.
Does anyone how how can I do it in matlab?

Risposta accettata

Chris Dan
Chris Dan il 31 Mar 2022
Modificato: Chris Dan il 31 Mar 2022
close all; clear all;
%% Data for Agglomerates
N = 1000; % number of spheres
a = 1; % lowest diameter of sphere
b = 200 ; % highest diameter of sphere
Diam = a + (b-a).*rand(N,1);
Diam = round(Diam);
aaa= 0; % minimum x and y coordinate limit for spheres
bbb= sum(Diam) ;% maximum x and y coordinat limit for sphere
M=3 ;
Axes= zeros(N,M);
Axes(:,1)=aaa+(bbb-aaa)*rand(N,1);
for k=2:M
aaa=randperm(N);
Axes(:,k)=Axes(aaa,1);
end
Axes_Label ={'X axis','Y axis','Z axis'};
Data_agglo = [Diam Axes];
Data_Label ={'Diameter','X axis','Y axis','Z axis'};
R = Diam ./2;
s = sum(Axes);
%% Plotting Agglomerates in 3D
f = figure('visible','on');
tic
for i =1:1:size(Data_agglo,1)
p = linspace(-Diam(i),Diam(i),200);
[X,Y,Z] = meshgrid(p,p,p); % box mesh
active = X.^2 + Y.^2 + Z.^2 <= R(i)^2 ;
plot3(Data_agglo(i,2)+X(active),Data_agglo(i,3)+Y(active),Data_agglo(i,4)+Z(active),'o');
hold on
end
hold all
toc

Più risposte (1)

Chris Dan
Chris Dan il 31 Mar 2022
found the answer in 2D
close all; clear all;
%% Data for Agglomerates
N = 100; % number of spheres
a = 1; % lowest diameter of sphere
b = 100 ; % highest diameter of sphere
Diam = a + (b-a).*rand(N,1);
Diam = round(Diam);
aaa= 1; % minimum x and y coordinate limit for spheres
bbb= sum(Diam) ;% maximum x and y coordinat limit for sphere
M=2 ;
Axes= zeros(N,M);
Axes(:,1)=aaa+(bbb-aaa)*rand(N,1);
for k=2:M
aaa=randperm(N);
Axes(:,k)=Axes(aaa,1);
end
Axes_Label ={'X axis','Y axis'};
Data_agglo = [Diam Axes];
Data_Label ={'Diameter','X axis','Y axis'};
R = Diam ./2;
s = sum(Axes);
%% Plotting Agglomerates in 2D
f = figure('visible','on');
for i =1:1:size(Data_agglo,1)
p = linspace(-Diam(i),Diam(i),200);
[X,Y] = meshgrid(p,p); % box mesh
active = X.^2 + Y.^2 <= R(i)^2 ;
plot(Data_agglo(i,2)+X(active),Data_agglo(i,3)+Y(active),'o');
hold on
end

Categorie

Scopri di più su Surfaces, Volumes, and Polygons in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by