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

3 Ansichten (letzte 30 Tage)
zeena alkateeb
zeena alkateeb am 20 Mär. 2020
Beantwortet: Yash am 20 Jul. 2025
I need a matlab program to draw a circle point-by-point with a spiral path, I have center and radius coordinates

Antworten (1)

Yash
Yash am 20 Jul. 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');

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by