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

4 vues (au cours des 30 derniers jours)
zeena alkateeb
zeena alkateeb le 20 Mar 2020
Réponse apportée : Yash le 20 Juil 2025
I need a matlab program to draw a circle point-by-point with a spiral path, I have center and radius coordinates

Réponses (1)

Yash
Yash le 20 Juil 2025
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');

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by