How to move a marker along line in polar coordinate

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

采纳的回答

Sulaymon Eshkabilov
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

更多回答(1 个)

Sulaymon Eshkabilov
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

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by