Making circular agglomerates using equation of circle

1 Ansicht (letzte 30 Tage)
Chris Dan
Chris Dan am 30 Mär. 2022
Bearbeitet: Chris Dan am 31 Mär. 2022
Hello,
I am trying to make circular agglomerates using this code, but it is plotting rectangles instead.
close all; clear all;
%% Data for Agglomerates
N = 5; % number of circles
a = 50; % lowest diameter of circles
b = 60 ; % highest diameter of cicles
Diam = a + (b-a).*rand(N,1);
Diam = round(Diam);
aaa= 1; % minimum x and y coordinate limit for circles
bbb= 5 ;% maximum x and y coordinat limit for circles
M=2 ;
Axes= zeros(N,M);
Axes(:,1)=aaa+(bbb-aaa)*rand(N,1);
for k=2:M
a=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'};
%% Plotting Agglomerates in 2D
R = Diam ./2;
f = figure('visible','on');
for i =1:1:size(Data_agglo,1)
p = linspace(Data_agglo(i,2),Data_agglo(i,3),10);
[X,Y] = meshgrid(p,p); % box mesh
active = (X.^2 + Y.^2 <= R(i)^2);
plot(X(active),Y(active),'o','MarkerFaceColor','blue');
hold on
end
hold on
the problem is with the active line or with the whole algorithm.Does anyone knows?

Akzeptierte Antwort

Chris Dan
Chris Dan am 31 Mär. 2022
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

Weitere Antworten (1)

Geoff Hayes
Geoff Hayes am 30 Mär. 2022
@hamzah khan - I think the problem is that diameters of your circles are too large given the limits you impose on your x and y variables. The diameter appears to be in the interval [50,60] yet your x and y limits are in the interval [1,5]. This would mean that all values in the meshgrid result would be considered to be "active" as per
active = (X.^2 + Y.^2) <= R(i)^2;
and so you would be plotting a rectangle instead of a circle. For example, the following code would create a circle given a radius of 2.5 with x and y in the interval [-10,10]
p = linspace(-10,10,1000);
[X,Y] = meshgrid(p,p); % box mesh
active = (X.^2 + Y.^2) <= 2.5^2;
plot(X(active),Y(active),'o','MarkerFaceColor','blue');
Note also how p is an array of 1000 elements. You could use fewer and I recommend that you experiment with this number. I think that the 10 you had is too small and so you won't necessarily get the circular shape that you are hoping for.
  3 Kommentare
Geoff Hayes
Geoff Hayes am 31 Mär. 2022
@hamzah khan - which part of your code determines or indicates the centre of the circle?
Chris Dan
Chris Dan am 31 Mär. 2022
Bearbeitet: Chris Dan am 31 Mär. 2022
Hii
I found the answer
close all; clear all;
%% Data for Agglomerates
N = 100; % 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 coordyinate 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by