Friday, 5 June 2009

Flower Bed

Recently I investigated Apollonian gaskets (a type of space-filling fractal composed of ever-repeating circles) for use as 'pore-space fillers' in a model I am creating for synthetic sediment beds. I came across a most excellent script here:

http://www.mathworks.com/matlabcentral/fileexchange/15987

In my Friday afternoon boredom, I have just modified some aspects of the program to create a function which simulates a pretty flower bed
function flower_bed(n)
% n is the number of internal circles (must be greater than 2 - greater than 10 looks weird)
h = figure;
hAxs = axes('Parent',h);
axis equal;
grid off;
hold on;
V = 0:2*pi/n:2*pi;
V = V +pi/2;
cV = cos(V);
sV = sin(V);
d = sqrt(diff(cV).^2+diff(sin(V)).^2);
r = d(1)/2;
ratio = max(max(max(abs(cV+r)),max(abs(sV+r))),...
max(max(abs(cV-r)),max(abs(sV-r))));
cV = cV/ratio;
sV = sV/ratio;
r = r/ratio;
r_inner1 = sqrt(cV(1).^2+sV(1).^2) - r;
for k=1:2:11
for j=1:2:11
S(1).x = [k,k,k+cV(1:end-1)];
S(1).y = [j,j,j+sV(1:end-1)];
S(1).r = [1,r_inner1,r*ones(1,n)];
hAxs = plot_circles(hAxs,S,1);
end
end
axis off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function hAxs = plot_circles(hAxs,S,n,display_style)
hold on
for t=1:size(S(n).x,2)
rectangle('Position',[S(n).x(t)-S(n).r(t),...
S(n).y(t)-S(n).r(t),2*S(n).r(t),2*S(n).r(t)],...
'Curvature',[1,1],'LineWidth',0.5,...
'tag',num2str(n),'Parent',hAxs,'EdgeColor','k','FaceColor',[rand rand rand]);
% plot(S(n).x(t),S(n).y(t),'k+','tag',num2str(n));
end
view raw flowerbed.m hosted with ❤ by GitHub
Some example outputs below - enjoy! Right, now back to work ...






No comments: