Making circular agglomerates using equation of circle
Show older comments
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?
Accepted Answer
More Answers (1)
Geoff Hayes
on 30 Mar 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 Comments
Chris Dan
on 31 Mar 2022
Geoff Hayes
on 31 Mar 2022
@hamzah khan - which part of your code determines or indicates the centre of the circle?
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!