Problem in Plotting Circles
1 次查看(过去 30 天)
显示 更早的评论
I am attaching part of a program whose target is to generate circles such that the distance between the center of the circles is normally distributed
Inputs:
1- Radius of the circle (same for all the)
2- Mean distance between circles ( I provide mean distance such that it must be greater than 2xradius. E.g if the radius of the circle is 0.25 then when the two circles are touching each other, the value of distance between centers of circles is 0.5. So let say if I provide value of mean as 0.58 so it means the average distance between the circles is 0.08 .
3- Variance ( In order to get variance, I divide the separation distance by 3, say if the separation between two circles is 0.08, then the variance is 0.08/3 i.e. 0.0266)
Problem No 1:
When I plot the circles then according to my definition, the circles may touch each other but SHOULD NOT overlap. However when I plot circles some of the circles over lap.
Problem 2:
I want to populate all the circles such that the geometry will remain in a box. Say if I plot a geometry of 5x5 circles, I don’t want any circle to go beyond 6 x 7 rectangular box. Can I do this by editing the code???
PLease find below the Actual Code :
nx = 20; % No of circles in x direction
ny = 25; % No of circles in y direction
m = 0.32; % Mean distance between circles
std = 0.0066; % Standard Deviation
ax= 0.15; % starting x co-ordinate i.e x cordinate of first circle
r= 0.15; %radius of circle
ay=0.15; % starting y co-ordinate i.e y c
%------Creating x and y co ordinates of n Circles-------------------------------------------------
Yoff = m +std*randn(ny-1,nx);
Xoff = m + std*randn(ny,nx-1);
Ycoord = cumsum( vertcat(ay*ones(1,nx), Yoff), 1);
Xcoord = cumsum( horzcat(ax*ones(ny,1), Xoff), 2);
%---------------------------- For Circles Plotting---------------------------------%
u=0:0.001:1; %degree
for y=1:nx
for x=1:ny
set(gca,'units','centimeters') % for units standarization
axpos = get(gca,'position'); % for units standarization
set(gca,'position',[axpos(1:2) abs(diff(xlim)) abs(diff(ylim))]) % for units standarization
axis equal % to make circles round
fill(Xcoord(x,y)+r*cos(2*pi*u),Ycoord(x,y)+r*sin(2*pi*u),'k'); % make circles of white in colour
hold on
end
end
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!