MATLAB How to create distinct circles in Matlab?

Click For Summary
Creating distinct circles in MATLAB can be achieved by generating random radii and centers while ensuring they do not overlap. The approach involves maintaining an Nx3 array where each entry holds the x-coordinate, y-coordinate, and radius of a circle. The first circle can be placed without constraints, while subsequent circles must pass a distance test to ensure they do not overlap with existing circles. This is done by calculating the distance between the new candidate circle's center and the centers of already placed circles, ensuring the distance exceeds the sum of their radii. Although initially considering an average distance between circles, this requirement was later abandoned in favor of a purely random placement approach, which has proven effective in MATLAB.
jamalkoiyess
Messages
217
Reaction score
22
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!
 
Physics news on Phys.org
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:
  • Like
Likes olivermsun
Nidum said:
Use random numbers to generate a mesh of triangles .
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
 
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.

jamalkoiyess said:
And if I want an average distance between them, how can I do it? (let's say 1 unit between one and the other)

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.
 
  • Like
Likes jamalkoiyess
Bubbles in triangles.jpg
 
  • Like
Likes olivermsun and jamalkoiyess
lewando said:
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.
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
Replies
1
Views
4K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K