How to Plot the Trajectory of a Point
2 views (last 30 days)
Show older comments
Allison Bushman
on 8 Dec 2018
Answered: Star Strider
on 8 Dec 2018
I am trying to plot the trajectory of P4 as it travels in the animation.
hold on
axis equal
axis off
b = 0:pi/60:pi/6;
c = 0:pi/30:pi/3;
d = 0:pi/20:pi/2;
for k = 1:numel(b)
P1=[-15,0];
P2=[-5,0];
plot([P1(1) P2(1)],[P1(2) P2(2)],'LineWidth',5,'Color','black');
A=[0,0];
h{1} = viscircles(A,5,'LineWidth',2,'Color','black');
B = A+[10*cos(b(k)-pi/6),10*sin(b(k)-pi/6)];
h{2} = viscircles(B,5,'LineWidth',2,'Color','green');
C = B+[10*cos(c(k)-pi/3),10*sin(c(k)-pi/3)];
h{3} = viscircles(C,5,'LineWidth',2,'Color','blue');
D = C+[10*cos(d(k)-pi/2),10*sin(d(k)-pi/2)];
h{4} = viscircles(D,5,'LineWidth',2,'Color','red');
P3=D+[5*cos(d(k)-(pi/2)),5*sin(d(k)-(pi/2))];
P4=D+[15*cos(d(k)-(pi/2)),15*sin(d(k)-(pi/2))];
h{5} = plot([P3(1) P4(1)],[P3(2) P4(2)],'LineWidth',5,'Color','black');
drawnow();
pause(0.5);
delete( vertcat(h{:}) );
end
hold off
axis equal
axis off
0 Comments
Accepted Answer
Star Strider
on 8 Dec 2018
Experiment with this:
P4vct = nan(numel(b),2); % Preallocate Before The ‘n’ Loop
then add these two lines after your ‘h{5}’ assignment:
P4vct(k,:) = P4;
h{6} = plot(P4vct(:,1),P4vct(:,2), '--','LineWidth',5,'Color','black');
It will then plot (what I believe to be) the ‘P4’ trajectory as a dashed black line.
That should at least give you an idea of the approach.
0 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots 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!