how to draw concentric circles with a random radios for first circle and next circles ploted with a period of 8 pixel respect to the inner circule?
3 views (last 30 days)
Show older comments
how to draw concentric circles with a random radios for first circle and next circles ploted with a period of 8 pixel respect to the inner circule?

0 Comments
Answers (1)
Satyam
on 26 Mar 2025
To draw concentric circles with a random initial radius and subsequent circles with a spacing of 8 pixels between them, leverage the "randi" function to choose the initial radius for the circle. You can go through the documentation of “randi” function to learn about the syntax. https://www.mathworks.com/help/matlab/ref/randi.html.
Since the spacing in pixels is relative to the zooming factor, so zooming in our out would change the scaling of the figure therefore the spacing would also change accordingly with respect to pixels. Hence, assuming that the spacing between the concentric circles is 8 units, here is a sample code explaining the approach taking into account the above assumption.
% Set the number of circles you want to draw
numCircles = 25;
% Generate a random radius for the first circle
initialRadius = randi([10, 50]);
% Define the period between circles
period = 8;
figure;
hold on;
axis equal;
grid on;
% Loop to draw each circle
for i = 0:numCircles-1
% Calculate the radius for the current circle
radius = initialRadius + i * period;
% Define the angle for the circle
theta = linspace(0, 2*pi, 100);
% Calculate x and y coordinates for the circle
x = radius * cos(theta);
y = radius * sin(theta);
% Plot the circle
plot(x, y, 'LineWidth', 1.5);
end
% Add labels and title
xlabel('X-axis');
ylabel('Y-axis');
title('Concentric Circles with Random Initial Radius');
hold off;
Hope this was helpful.
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!