plot multiple circles within polygon with fixed radius and at particular distance from each other ?

조회 수: 5 (최근 30일)
Hi!
I have to plot many circles within polygon with fixed radius and at known or fixed distance from each other. I am plotting each circle manually, this makes my code lengthy. Also i have to calculate the distance of circle's center point from other circles. Is there any way to plot circles using loop or any other method??? help plz

답변 (2개)

Image Analyst
Image Analyst 2016년 11월 20일
viscircles(), introduced in R2012a of the Image Processing Toolbox, will plot a bunch of circles all in a single line of code. Just supply the centers and radii.

John D'Errico
John D'Errico 2016년 11월 20일
With a slightly bemused look on my face. :) Nope. It is simply impossible to use a loop.
Seriously, of course you can use a loop to plot circles. You really done't even need loop, since in fact you can plot as many circles as you wish at one time with one call to plot. So no loop is needed at all.
Given the coordinates of the center of each circle and the known radius, compute points around the perimeter of a circle using a transformation from polar coordinates. I.e., if theta varies over [0,2*pi], then
x = C_x+r*cos(theta)
y = C_y+r*sin(theta)
So you can generate all of the circle perimeters in one line if you do it carefully. Plot them all in one more line of code, again using the right call to either plot or line. (Read the help for those tools.)
The problem is in finding the circle centers, within a completely general polygon. This is what would be called a circle packing problem (sphere packing in higher dimensions.) Not totally trivial.
  댓글 수: 1
Image Analyst
Image Analyst 2016년 11월 20일
I didn't even attempt to find the centers because you're right it's complicated and would have multiple solutions. For his remaining question, assuming he has the centers already, and needs to answer "i have to calculate the distance of circle's center point from other circles", he can use pdist2() in the Statistics and Machine Learning Toolbox to calculate the distance between every center and every other center, unless he's talking about the Hausdorf Distance which is doubtful.

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by