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

15 次查看(过去 30 天)
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 个评论
Sandeep Kumar
Sandeep Kumar 2021-9-28
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

请先登录,再进行评论。

采纳的回答

Johan
Johan 2021-9-27
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 个评论
Sandeep Kumar
Sandeep Kumar 2021-9-28
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 2021-9-30
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

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2021-9-27
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 个评论
Sandeep Kumar
Sandeep Kumar 2021-9-29
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 2021-9-29
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by