Making circular shapes using equation of circle
6 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Geoff Hayes
on 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 Comments
Geoff Hayes
on 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?
More Answers (1)
Image Analyst
on 5 Apr 2022
I think using the viscircles() function would be much simpler. Would that work for you?
See Also
Categories
Find more on 2-D and 3-D Plots 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!