# non overlapping random circles

52 ビュー (過去 30 日間)
jahanzaib ahmad 2019 年 2 月 20 日
コメント済み: Adam Danz 2019 年 5 月 29 日
in search of a code which can generate output like this on matlab . and the result is in polyshapes ,centre and radius
circles are randomly distributed at the periphery of square .
input is number of circels,max radius , minimum radius and area of circles

サインインしてコメントする。

### 採用された回答

Adam Danz 2019 年 2 月 20 日

The FEX contribution metioned by Matt J produces cirlces that are closely packed. I wrote an alternative function that plots circles with random centers that do not overlap but do not have the requirement to be densely packed. That function can be downloaded here:
Here are some notes that pertain to your needs:
• One of the parameters you can set is whether the circles extend beyond the chosen border or not.
• At the top of the code, in the comment section, I give an example of how to calculate the area of the circles by using the function outputs.
Please feel free to play around with that function and its options. If you have any further question or problems, please follow up here.
Below are some examples produced by this funciton.
*A previous version of this solultion included the source code. I've since edited that code and uploaded it to the file exchange.

#### 8 件のコメント

jahanzaib ahmad 2019 年 2 月 21 日
Matt J 2019 年 5 月 29 日
Mehdi Mousavi's comment moved here:
I cannot run your function. actually I ran it as the following code:
and the error is:
Error in bubblebath (line 131)
Regards
Mehdi
Adam Danz 2019 年 5 月 29 日
What's the full error message (copy-pasted)?

サインインしてコメントする。

### その他の回答 (1 件)

Matt J 2019 年 2 月 20 日

Perhaps one of these FEX contributions would be helpful.

#### 3 件のコメント

jahanzaib ahmad 2019 年 2 月 20 日
its not a packing problem are cirlces are not fully inside box ,
Matt J 2019 年 2 月 20 日
But perhaps you can post-process the results according to your needs, e.g., discard circles above/below the minimum radius and randomly modulate the radii of circles that remain.
Adam Danz 2019 年 2 月 20 日
The circles aren't fully inside of the frame in the example you provided either.

サインインしてコメントする。

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by