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

14 views (last 30 days)
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 Comment
Sandeep Kumar
Sandeep Kumar on 28 Sep 2021
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

Sign in to comment.

Accepted Answer

Johan
Johan on 27 Sep 2021
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 Comments
Sandeep Kumar
Sandeep Kumar on 28 Sep 2021
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
Johan
Johan on 30 Sep 2021
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

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 27 Sep 2021
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 Comments
Sandeep Kumar
Sandeep Kumar on 29 Sep 2021
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!
Image Analyst
Image Analyst on 29 Sep 2021
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.

Sign in to comment.

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!