How to plot multiple circles within a circle by using a for-loop for radius/center position?

Hi,
I want to plot multiple equisized small circles filling within a sector bigger circle.
The center of each of the smaller circle changes as radial distance with respect to the center of bigger cirlce, as can be seen from the attached image. And the smaller circles are to be filled with color map, ranging from 0 to 1.
This entire plotting will then be in a time loop from 1 to 100 sec.
It will be of great help if anyone can share thoughts, and if possible, brief code.
Thanks!
Sandeep

1 commentaire

Hi,
Since, I am sort of rookie in using Matlab, I am not able to process the function properly and use it.
Can you elaborate a bit more by plotting demonstration one, if possible. It will be very helpful.
Thanks!
Best Regards,
Sandeep

Connectez-vous pour commenter.

 Réponse acceptée

Hi,
I have been working with somewhat similiar plotting needs. To plot circles I used the polyshape built-in function with the code below. With this function you can directly call plot(CoordCircle(radius,xcenter,ycenter) and update your plot following your needs. You can look up the polyshape function for details on plotting, you can change transparency and color as suits your need.
function RES = CoordCircle(r,x0,y0)
t = 0:0.05:2*pi;
x1 = r*cos(t)+x0;
y1 = r*sin(t)+y0;
RES = simplify(polyshape(x1,y1));
end
To make your time depend representation, I would start by plotting all the circles you want, compute the new radii then update your plotted circle by using the figure handle, clf and drawnow function.
Hope this helps,
Johan

5 commentaires

Hi,
Thank you for the reply.
Since, I am sort of rookie in using Matlab, I am not able to process the function properly and use it.
Can you elaborate a bit more by plotting demonstration one, if possible. It will be very helpful.
Best Regards,
Sandeep
@Sandeep Kumar, if it's confusing to you, you can try viscircles() like I suggested below. Did you try that?
Hi,
to use a function like the one I sent previously, you need to put the code of the function in a single matlab file and save it in your matlab repository. You will then be able to call that function from another matlab file. Note that, as Image Analyst suggested, if you have access to the Image Processing Toolbox you can simply call the viscircles function instead.
Here is an example of a shrinking circle:
%initial parameters
r0 = 5;
x = 0;
y = 0;
%creates a figure
myfigure = figure;
hold on
for t = 1:100
%update radius
r = r0*(1-0.5*(t/100));
%clear axis to remove previous plot
cla
%set axis limit
xlim([-6,6])
ylim([-6,6])
%plot circle
% plot(CoordCircle(r,x,y),'FaceColor',[1,0,0],'EdgeColor',[0,1,0]) %
viscircles([x,y],r);
pause(1/21) %pause 0.5
end
hold off
Best,
Johan
Hi,
Thank you for the reply.
It is really giving me hope that I will be able to get the plot as I expect.
Now, please help me with couple of more things:
1) is there a way to have the smaller circles, basically there (x,y, r) within the boundary (circumference) limit of bigger circle. So, that the center for small circles does not get outside the bigger circle.
2) Can I use colormap to fill the small circles within bigger circle within the color range of 0 to 1.
Best Regards,
Sandeep
1) Yes you can plot two circle at the same x,y but with different r and use the option.
plot(...., 'FaceAlpha', 0)
to make one circle's interior transparent.
If you need to limit the radius or center of a circle compared to another you will need to set condition to your x,y,r parameters before you plot.
2) I'm not sure exactly what you mean, if you want matlab to handle the colors automatically you can remove the 'FaceColor',[1,0,0] option of the plot.
Best,
Johan

Connectez-vous pour commenter.

Plus de réponses (1)

If you have a list of the centers and radii, and the Image Processing Toolbox, I'd simply use the function meant for displaying circles: viscircles()
viscircles(centers, radii);
Lots of options you can use to change the way the circles look (color, linewidth, etc.), so look into those.

4 commentaires

Hi,
Thank you for the reply.
It is really giving me hope that I will be able to get the plot as I expect.
Now, please help me with couple of more things:
1) is there a way to have the smaller circles, basically there (x,y, r) within the boundary (circumference) limit of bigger circle. So, that the center for small circles does not get outside the bigger circle.
2) Can I use colormap to fill the small circles within bigger circle within the color range of 0 to 1.
Best Regards,
Sandeep
  1. Not with viscircles(). There is no masking feature for that function. You'd have to do the masking yourself by manually drawing the arcs.
  2. Not with viscircles(). You'd have to create a digital RGB image and then you could synthesize such an image.
Hi,
Unfortunately, I am not skilled enough to make these in Matlab.
It will be great if you can share some pointers on how to make pt. 1 and pt. 2.
Also, I have the radial distance from center of bigger circle to the smaller circles.
Now, how can I make several small circles witihn the bigger circle by change the center coordinates from 0 to 360o at the same radial distance (from center of bigger circle)?
Thanks!
To plot an arc, see the FAQ:
You'd have to figure out the starting and stopping angle. That part is not MATLAB - it's just pure 10th grade math/geometry so I'm sure you can do it. Worst case you can plot just a point and a time and check if the point is farther away or closer from the containing circle's center than the containing circle's radius. Plot a dot if it's closer and don't plot a dot if it's farther away. Use sqrt() to get the Euclidean distance using the Pythagorean theorem.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Produits

Version

R2021a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by