# Matlab How to create distinct circles in Matlab?

Tags:
1. May 11, 2017

### jamalkoiyess

I want to create a plate of distinct circles on Matlab where their radii are generated by randn(1,p) and centers are random. I am currently doing the circles using viscircles, but some of them are overlapping, and since I want approximately 100 ones, this problem only gets worse.
How can I make them so they are distinct? And if I want an average distance between them, how can I do it? (let's say 1 unit between one and the other)
Thank you!

2. May 11, 2017

### Nidum

Use random numbers to generate a mesh of triangles .

In fill the triangles with circles .

You can use rules to control shape factors and relative sizes of triangles if you want to .

Last edited: May 15, 2017
3. May 11, 2017

### jamalkoiyess

How can I do that? I am a total beginner at Matlab so can you please go a bit easy on me if you can. Thank you

4. May 15, 2017

### lewando

I can't readily see how to do this with a triangular mesh (too early in the morning, perhaps). I can probably imagine how to do it with a simple rectangular grid, with each cell containing one circle of random radius and position. A test would have to be performed on x, y, and r to make sure is completely inside a cell. What I don't like about that approach is the reduction in randomness even though circles can be randomly located within a cell.

A more random approach might be this: maintain an Nx3 array, where each N index would contain xN, yN, and rN. N could be exactly 100 which satisfies your "approximately 100" requirement. Placement of circle N=1 (C1) is easy because there are no constraints. Placement of candidate circle C2 would have to pass a test before it could be added to the array and placed on the field. You can compute the distance between x1, y1 and the new candidate location. If this distance is greater than the sum of r1 and rcandidate, then you can add it to the array and place it on the field. For candidate circle C3, it would have to pass the test against C2 and C1. And so on.

If you want a specific average distance between the circles' edges, then this constraint in conflict with the random size and location constraint. I would ask you to provide the context that drives this necessity.

5. May 15, 2017

### Nidum

6. May 23, 2017

### jamalkoiyess

I did the random approach you suggested yesterday. I tested it on Java and took the arrays to matlab. It is working great. And I just abandoned the requirement for the average distance between cirlces.
Thank you.