How plot a messy random-size circles in MATLAB? -


i going draw figure such below picture in matlab r2014b: messy circles.

this figure consists of many circles different (random) colors , random sizes.

how possible plot such figure in matlab r2014b?

without spelling out code:

  1. pick initial circle, e.g. position [0,0] , radius 1.
  2. initialise list positions , radii.
  3. pick random position , radius r.
  4. if circle not in big 1 (i.e. sqrt(pos(1)^2+pos(2)^2) + r > 1) continue 3.
  5. if overlap other circles (distance between positions > sum of radii), continue 3
  6. add circle list, continue 3

update: example

alright, wanted try this. i'm sure not best implementation, but:

% set number of circles plot n = 200; radii = zeros(n, 1); pos = zeros(n, 2); allcolours = lines(n); % main loop idx = 1:n     is_good = false;     % generate random positions , radii until have hit     while ~is_good         pos(idx, :) = rand(1, 2)*2 - 1;         radii(idx) = rand * (1 - max(radii));         if ((sqrt(sum(pos(idx, :).^2)) + radii(idx) ) < 1) ... % ensure we're inside big circle                 && ((idx == 1) || ... %  , either it's first circle, or                 all(sqrt(sum((pos(1:(idx-1), :) - repmat(pos(idx, :), idx-1, 1)).^2, 2)) > radii(1:(idx-1))+radii(idx))) % distances bigger sum of radii of existing circles             is_good = true;         end     end end %% plot figure(2); clf;  hold on set(gca, 'visible', 'off') daspect([1, 1, 1]) rectangle(...     'position',[-1 -1 2 2],...     'curvature', [1 1],...     'facecolor', 'none',...     'edgecolor', [ 0, 0, 0]); idx = 1:n     rectangle(...         'position',[pos(idx, 1) - radii(idx), pos(idx, 2) - radii(idx), 2*radii(idx), 2*radii(idx)],...         'curvature', [1 1],...         'edgecolor','none',...         'facecolor', allcolours(idx,:)); end 

example output


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -