How to create distinct circles in Matlab?

In summary, the conversation discusses generating a plate of distinct circles on Matlab using random numbers for the radii and centers. The current method of using viscircles is causing overlap and the person wants approximately 100 circles. They ask for a solution to make the circles distinct and also inquire about setting an average distance between them. A suggestion is made to use a random approach where an array is maintained with x, y, and r values for each circle, and a test is performed to ensure they do not overlap. The idea of a specific average distance is questioned and ultimately abandoned. The person confirms that the random approach suggested is working well for them.
  • #1
jamalkoiyess
217
21
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
  • #2
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
  • #3
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
 
  • #4
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
  • #5
Bubbles in triangles.jpg
 
  • Like
Likes olivermsun and jamalkoiyess
  • #6
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.
 

1. How do I create a circle in Matlab?

To create a circle in Matlab, you can use the "circle" function in the Image Processing Toolbox. This function takes in the center coordinates, radius, and number of points to use in creating the circle. You can also use the "rectangle" function and specify the width and height to be equal to the diameter of the circle, to create a circle-shaped plot.

2. Can I customize the properties of the circle in Matlab?

Yes, you can customize the properties of the circle in Matlab by using the "plot" function. This function allows you to specify the line style, color, and thickness of the circle. You can also use the "fill" function to fill the circle with a specific color.

3. How can I create multiple circles in one plot in Matlab?

To create multiple circles in one plot in Matlab, you can use a for loop to iterate through the coordinates and radius of each circle and plot them using the "circle" or "rectangle" function. You can also use the "hold on" command to prevent the previous plot from being cleared, allowing you to create multiple circles in one plot.

4. Is it possible to create a circle with a gradient color in Matlab?

Yes, you can create a circle with a gradient color in Matlab by using the "patch" function. This function allows you to specify the center coordinates, radius, and color of the circle, as well as the "FaceColor" property to create a gradient effect. You can also use the "colormap" function to customize the color gradient.

5. Can I create a 3D circle plot in Matlab?

Yes, you can create a 3D circle plot in Matlab by using the "sphere" function. This function creates a 3D sphere with a specified radius and center coordinates. You can also use the "surf" function to create a 3D surface plot of the circle, allowing you to customize the color and shading of the circle.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
752
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
Replies
4
Views
831
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
Back
Top