Making circular shapes using equation of circle

5 visualizzazioni (ultimi 30 giorni)
Hello,
I am trying to make circular shapes using this code, but it is plotting half circles or quater circles instead.
close all; clear all;
%% Data for Agglomerates
N = 2; % number of circles
a = 1; % lowest diameter of circles
b = 5 ; % highest diameter of circles
Diam = a + (b-a).*rand(N,1);
Diam = round(Diam);
aaa= 0; % minimum x and y coordyinate limit for circles
bbb= sum(Diam); % 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
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;
%% generate mesh
xmin = min(Data_agglo(:,2)-R);
xmax = max(Data_agglo(:,2)+R);
ymin = min(Data_agglo(:,3)-R);
ymax = max(Data_agglo(:,3)+R);
[Xgrid,Ygrid]= meshgrid(linspace(xmin,xmax,200), linspace(ymin,ymax,200));
plot(Xgrid,Ygrid,'k',Ygrid,Xgrid,'k')
hold all
%% get active dipoles
for i =1:1:size(Data_agglo,1)
active = Xgrid.^2 + Ygrid.^2 <= R(i).^2;
hold on
plot(Data_agglo(i,2)+Xgrid(active),Data_agglo(i,3)+Ygrid(active),'o');
% plot(Xgrid(active),Ygrid(active),'o','MarkerFaceColor','red');
hold on
end
the problem is with the active line or with the whole algorithm.Does anyone knows?

Risposta accettata

Geoff Hayes
Geoff Hayes il 5 Apr 2022
@hamzah khan - I think the issue is with the bounds for your grid
xmin = min(Data_agglo(:,2)-R);
xmax = max(Data_agglo(:,2)+R);
ymin = min(Data_agglo(:,3)-R);
ymax = max(Data_agglo(:,3)+R);
Once, when running the code, there were no partial or full circles drawn. This was with the following
Diam = [1;4];
Data_agglo = [1.0000 2.4709 2.4709;...
4.0000 3.8953 3.8953];
creating intervals for x and y as
x : [1.8953 5.8953]
y : [1.8953 5.8953]
and radii of
0.5
2
Given the intervals for x and y, then I don't see how any (x,y) pair would satisfy square of either radius. I think that you need to take into account the centre of the circle when finding the active set of elements in the circle
%% get active dipoles
for i =1:1:size(Data_agglo,1)
active = ((Xgrid - Data_agglo(i,2)).^2 + (Ygrid - Data_agglo(i,3)).^2) <= R(i).^2;
hold on
plot(Xgrid(active),Ygrid(active),'o');
end
  4 Commenti
Geoff Hayes
Geoff Hayes il 6 Apr 2022
@hamzah khan - I'm not sure how it can be done in 3D (haven't tried to do this before). Can you post the code and the full error message?
Chris Dan
Chris Dan il 7 Apr 2022
I have done it in 3D, here is my code :
close all; clear all;
%% Data for Agglomerates
N = 15; % number of spheres
a = 1; % lowest diameter of sphere
b = 10 ; % highest diameter of sphere
Diam = a + (b-a).*rand(N,1);
Diam = round(Diam);
aaa= 0; % minimum center x and y coordinate limit for spheres
bbb= sum(Diam) ; % maximum center x and y coordinat limit for sphere
% bbb= N*((1+sqrt(5))/2); % maximum center 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;
%% generate mesh
Nn = 50;
xmin = min(Data_agglo(:,2)-R);
xmax = max(Data_agglo(:,2)+R);
ymin = min(Data_agglo(:,3)-R);
ymax = max(Data_agglo(:,3)+R);
zmin = min(Data_agglo(:,4)-R);
zmax = max(Data_agglo(:,4)+R);
[Xgrid,Ygrid,Zgrid]= ndgrid(linspace(xmin,xmax,Nn), linspace(ymin,ymax,Nn), linspace(zmin,zmax,Nn));
% plot3(Xgrid(:),Ygrid(:), Zgrid(:),'.','MarkerFaceColor','blue');
% hold all
%% get active dipoles
tic
for i =1:1:size(Data_agglo,1)
active = ((Xgrid - Data_agglo(i,2)).^2 + (Ygrid - Data_agglo(i,3)).^2 + (Zgrid - Data_agglo(i,4)).^2) <= R(i).^2;
% plot3(Xgrid(active),Ygrid(active),Zgrid(active),'.r');
plot3(Xgrid(active),Ygrid(active),Zgrid(active),'o','MarkerFaceColor','red');
hold all
end
axis equal
grid on
toc
The only confusion I have is that for 2D and for 3D I am creating active for each circle in the for loop, would it be possible that i create it for all circles without the loop. One matrix of active which has 1s and 0s for all the circles and than i plot it

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 5 Apr 2022
I think using the viscircles() function would be much simpler. Would that work for you?
  1 Commento
Chris Dan
Chris Dan il 6 Apr 2022
Hii,
no I have to use a grid to find out which points are inside the spheres

Accedi per commentare.

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by