draw a circle point-by-point with a spiral path

5 次查看(过去 30 天)
I need a matlab program to draw a circle point-by-point with a spiral path, I have center and radius coordinates

回答(1 个)

Yash
Yash 2025-7-20
Refer to below code snippet to draw a spiral that starts from the circle's center and stops at the circumference.
xc = 5; % x-coordinate of center of circle
yc = 7; % y-coordinate of center of circle
r = 4; % radius of circle
theta_max = 6*pi; % turns in spiral, spiral reaches radius at theta_max
n_points = 1000; % points in spiral
t = linspace(0, theta_max, n_points);
max_r_spiral = r;
a = 0;
b = max_r_spiral / theta_max;
% Spiral path (polar coordinates)
spiral_r = a + b * t;
spiral_x = xc + spiral_r .* cos(t);
spiral_y = yc + spiral_r .* sin(t);
figure;
hold on;
axis equal;
plot(xc, yc, 'ko', 'MarkerFaceColor','k');
theta = linspace(0, 2*pi, 200);
plot(xc + r*cos(theta), yc + r*sin(theta), 'k--'); % reference circle
for k = 1:n_points
plot(spiral_x(k), spiral_y(k), 'ro', 'MarkerSize', 3, 'MarkerFaceColor','r');
pause(0.01);
end
title('Circle point-by-point with a Spiral Path');

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by