How to Plot the Trajectory of a Point

조회 수: 5 (최근 30일)
Allison Bushman
Allison Bushman 2018년 12월 8일
답변: Star Strider 2018년 12월 8일
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

채택된 답변

Star Strider
Star Strider 2018년 12월 8일
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개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by