How to move a marker along line in polar coordinate

3 Ansichten (letzte 30 Tage)
ロン
ロン am 10 Feb. 2023
I want to draw a point that can move along to the Lemniscate of Bernoulli in polar coordinate. The example to move object along to a line is shown in this URL:https://www.mathworks.com/help/matlab/creating_plots/move-group-of-objects-along-line.html
The following code is the my try to realize my target. But it just can animate a line in coordinate system:
clear;
theta = -pi/4:0.001:0; % cosine of 2*theta will be positive for this range
r = -sqrt(cos(2*theta));
figure;
polarplot(theta, r, 'b', 'LineWidth',1.0);
hold on
h = animatedline;
rlim([0 1]);
h.LineWidth = 1.5;
h.LineStyle = ":";
h.Color=[1 0 0] ;
n= length(theta);
for k = 1:length(theta)
addpoints(h,theta(k),r(k))
drawnow
end

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 10 Feb. 2023
Here it is:
clear;
theta = -pi/4:0.001:0; % cosine of 2*theta will be positive for this range
r = -sqrt(cos(2*theta));
figure;
polarplot(theta, r, 'b', 'LineWidth',1.0);
hold on
H = animatedline('Marker', 'o', 'MaximumNumPoints',1);
for k = 1:length(theta)
addpoints(H,theta(k),r(k));
drawnow
end
  2 Kommentare
ロン
ロン am 10 Feb. 2023
Thank you very much. It works! You help me a lot
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 10 Feb. 2023
Most welcome. Glad to help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 10 Feb. 2023
Here is the corrected plot that animates a marker.
clear;
theta = -pi/4:0.001:0; % cosine of 2*theta will be positive for this range
r = -sqrt(cos(2*theta));
figure;
polarplot(theta, r, 'b', 'LineWidth',1.0);
hold on
H = animatedline('Marker', 'o');
rlim([0 1]);
n= length(theta);
for k = 1:n
addpoints(H,theta(k),r(k))
drawnow
end

Kategorien

Mehr zu Polar Plots 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