Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
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

Réponses (2)

Image Analyst
Image Analyst le 20 Nov 2016
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 le 20 Nov 2016
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 commentaire
Image Analyst
Image Analyst le 20 Nov 2016
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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by