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?

4 次查看(过去 30 天)
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?

回答(1 个)

Satyam
Satyam 2025-3-26
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.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by