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
Capture.PNG

 채택된 답변

Adam Danz
Adam Danz 2019년 2월 20일
편집: Adam Danz 2019년 2월 21일

1 개 추천

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.
190221 111913-Figure 4.jpg
*A previous version of this solultion included the source code. I've since edited that code and uploaded it to the file exchange.

댓글 수: 10

jahanzaib ahmad
jahanzaib ahmad 2019년 2월 20일
@Adam Danz my required output is different . circles are at the pheriphery as well.but only that part is drawn which is inside box .
jahanzaib ahmad
jahanzaib ahmad 2019년 2월 20일
and i wanted to find the area of those circles . complete circles and incomplete circles thats y i asked output to be in polyshapes
Matt J
Matt J 2019년 2월 21일
편집: Matt J 2019년 2월 21일
But is the pattern of circles generated in my solution or Adam's acceptable or not? That's the challenging part. Once we've given you code that generates a proper pattern of circles, it should be a trivial matter for you reformat the output as polyshapes yourself.
jahanzaib ahmad
jahanzaib ahmad 2019년 2월 21일
편집: jahanzaib ahmad 2019년 2월 21일
dear sir
output is different what i have requested . i want to generate circles on pheriphery as well and draw the part that is inside the square box only .and find the over all area . i didnt find anything like this oon mathworks .
Adam Danz
Adam Danz 2019년 2월 21일
편집: Adam Danz 2019년 2월 21일
jahanzaib ahmad, I've edited my solution. Please see the link in my answer above and feel free to play around with the function that has been adapted to suit your needs.
Specifically, you can use the outputs of that function to add polyshapes and to calculate area. See the examples I've provided within the function file.
jahanzaib ahmad
jahanzaib ahmad 2019년 2월 21일
@ Adam Danz thanks alot
Mehdi Mousavi's comment moved here:
I cannot run your function. actually I ran it as the following code:
[Cen,Rad] = bubblebath()
and the error is:
Error in bubblebath (line 131)
radMat = xyr(:,3) + xyr(:,3)';
please help me in using your code
Regards
Mehdi
Adam Danz
Adam Danz 2019년 5월 29일
What's the full error message (copy-pasted)?
DIVAKAR RAJU P V
DIVAKAR RAJU P V 2021년 1월 21일
can we maintain periodicity here. cutout portion of boundary should fall on opposite side
Yes, starting in bubblebath() vs 2.3.0 you can set edgeType=3 to wrap circles that expand beyond the frame edge.
Example:
rng('default') % for reproducibility
S = struct();
S.frameSize = [30 30];
S.circSize = 4;
S.nSizes = NaN;
S.edgeType = 3; % <-- flag to wrap edges
S.supressWarning = true;
bubblebath(S)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2019년 2월 20일
편집: Matt J 2019년 2월 20일

0 개 추천

Perhaps one of these FEX contributions would be helpful.

댓글 수: 3

jahanzaib ahmad
jahanzaib ahmad 2019년 2월 20일
1pcf4.png its not a packing problem are cirlces are not fully inside box ,
Matt J
Matt J 2019년 2월 20일
편집: 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
Adam Danz 2019년 2월 20일
The circles aren't fully inside of the frame in the example you provided either.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Elementary Polygons에 대해 자세히 알아보기

질문:

2019년 2월 20일

댓글:

2021년 1월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by