How to move a marker along line in polar coordinate
1 view (last 30 days)
Show older comments
ロン
on 10 Feb 2023
Commented: Sulaymon Eshkabilov
on 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
0 Comments
Accepted Answer
Sulaymon Eshkabilov
on 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 Comments
More Answers (1)
Sulaymon Eshkabilov
on 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
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!