0

I have written a MATLAB code to be able to visualize some Circles. Please have a look at my below code and the attached figure as the output.

clc;
clear;
close all;

% X and Y of each Center
Xloc = [1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5];
Yloc = [1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5];

% Radius of each circle
radius = unifrnd(0,1,[1 numel(Xloc)]);

% Random colours
allColours = rand(numel(Xloc),3);

% Transform the data into position = [left bottom width height]
pos = [Xloc(:)-radius(:) Yloc(:)-radius(:) 2*radius(:)*[1 1]];

% Create and format the axes
H = axes;
hold on;
axis equal;
box on;
set(H,'XTickLabel',[],'YTickLabel',[]);

% Create the circles
for idx = 1:numel(Xloc);
    rectangle(...
        'Position',pos(idx,:),...
        'Curvature',[1 1],...
        'FaceColor',allColours(idx,:),...
        'EdgeColor','none');
end

The output figure is (Circles' radius is generated randomly, so if you execute the code, you will face with a new output):

Circles

As you can see in the figure, there is overlap between circles. I was wondering how can I separate centers from each other to do not overlap each others, and at the same time they keep the original distance (or similar distance) from each other in [Xloc Yloc]

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • reduce the radii? – Ander Biguri Mar 09 '17 at 13:17
  • @AnderBiguri , the radius shows the spread of the circle, it means that the highest radii stands for the most important circle – Ahmad Namvar Mar 09 '17 at 16:12
  • I have no idea how that information helps. You have circles. You dont want to change their positions. You want them not to touch. Make them smaller is the only option – Ander Biguri Mar 09 '17 at 16:12
  • @AnderBiguri Alright. I am going to make it easier. I can change the positions, but my main concern is: (1) keep radii (2) keep the distance because distance shows the contribution between them. So, I should find a solution to be able to do that properly. – Ahmad Namvar Mar 09 '17 at 16:27
  • @AhmadNamvar you mean keep relative distance? Because keep distance means do not change their position. Can you show a fake image on how you want it to look? – Ander Biguri Mar 09 '17 at 16:30

1 Answers1

0

You can try to formulate an optimisation problem:

  • You have to constrain the minimal distance between the centers based on the desired radii.
  • You have to minimise the deviations from its desired center location.
m7913d
  • 10,244
  • 7
  • 28
  • 56
  • Just for drawing some circles without overlapping, could not be a good solution. I think we can sort it out with a lightweight solution. – Ahmad Namvar Mar 09 '17 at 16:10
  • It should not be that difficult to implement, but you are free to use whatever method you prefer. This is just a possibility, which allows you to formulate exactly what you want. – m7913d Mar 09 '17 at 17:37