Trajectory animation using coordinate points

79 次查看(过去 30 天)
I have set of x, y and z coordinates of two objects and I want to create animation of the object's 3D trajectory/motion using these coordinates. Consider the first coordinate in the set as the initial position. Can anyone help me with this.

采纳的回答

darova
darova 2019-9-1
Animation it is just changing of images like in cartoons
plot(x,y,z)
hold on
for i = 1:length(x)
h = plot(x(i),y(i),z(i),'^r'); % draw something on the trajectory
pause(0.2) % wait a minute
delete(h) % delete it
end
hold off

更多回答(1 个)

David K.
David K. 2019-8-30
编辑:David K. 2019-9-3
I would do it like this:
% x1,x2,y1,y2,z1,z2 are your coordinate vectors
tstep = .1; % the amount of time between each value in the vectors
figure(1)
for n = 1:length(x1)
plot3(x1(1:n),y1(1:n),z1(1:n),'+-',x2(1:n),y2(1:n),z2(1:n),'+-')
title((n-1)*tstep); % label the time of each step
pause(.01)
end
If the default view of the plot is bad mess around with the view function to try and get a better one.
This will make an animation with both, to make the other two animations simply repeat it and leave out the xyz coordinates of the one you do not want to look at.
edit: fixed so it should actually work now
  6 个评论
Tomer
Tomer 2019-9-1
编辑:Tomer 2019-9-1
See, the attachment
tstep = .1; % the amount of time between each value in the vectors
figure(1)
for n = 1:length(x)
plot3(x,y,z,'+-')
title((n-1)*tstep); % label the time of each step
pause(.01)
end
I could see only the plot but, not the animation video.
David K.
David K. 2019-9-3
Oh woops the plot3 should actually be this, i've also updated my original answer with it.
plot3(x(1:n),y(1:n),z(1:n),'+-')
Then, the axis will auto update as the values are added. If you do not want the line change '+-' to '+'
You also may need to add this to it to hold the axis positions.
xlim([lowX upX]);ylim([lowY upY]);zlim([lowZ upZ]);

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by