How to create distinct circles in Matlab?

Click For Summary

Discussion Overview

The discussion focuses on generating distinct circles in Matlab, specifically addressing the creation of circles with random radii and positions while avoiding overlaps. Participants explore various methods for achieving this, including triangular meshes and rectangular grids, and discuss the challenges of maintaining randomness while ensuring circles do not overlap.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant suggests using random numbers to generate a mesh of triangles filled with circles, but does not provide details on implementation.
  • Another participant expresses a desire for a simpler approach using a rectangular grid, where each cell contains one circle with random radius and position, but notes the potential reduction in randomness.
  • A more detailed method is proposed involving an Nx3 array to store circle parameters, with conditions for adding new circles based on distance checks to avoid overlaps.
  • Concerns are raised about the conflict between maintaining a specific average distance between circles and the randomness of their sizes and locations.
  • A later reply indicates that one participant abandoned the requirement for average distance after testing a suggested approach in Java and successfully implementing it in Matlab.

Areas of Agreement / Disagreement

Participants present multiple competing views on how to generate distinct circles, with no consensus on a single method. Some methods are proposed, but challenges and conflicts in requirements remain unresolved.

Contextual Notes

Participants express uncertainty regarding the implementation of triangular meshes and the implications of maintaining randomness while ensuring circles do not overlap. The discussion also highlights the complexity of balancing size and distance constraints.

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   Reactions: 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   Reactions: jamalkoiyess
Bubbles in triangles.jpg
 
  • Like
Likes   Reactions: 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 4 ·
Replies
4
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
1
Views
4K
Replies
2
Views
2K