Plotting trajectory from displacement/time history

I have position data for four points (origin, x, y, and z) which determine a coordinate system. How can I plot the coordinate system trajectory using this data? I would like to have a continuous line for the origin and evenly spaced vectors showing the orientation of the coordinate system.
Thank you in advance.

 採用された回答

Jonathan Epperl
Jonathan Epperl 2012 年 11 月 16 日

0 投票

It would be nice had you included some sample data, so I made up my own, I hope it is somewhat similar
t = linspace(0,pi)';
% Origin
O = [sin(t),cos(t),t.^2];
%
X = O + [ones(1e2,1) rand([1e2 2])*.1];
Y = O + [rand([1e2 1])*.1 ones(1e2,1) rand([1e2 1])*.1];
Z = O + [rand([ 1e2 1])*.1 rand([ 1e2 1])*.1 ones(1e2,1) ];
You'll need a function that plots arrows, I'm not sure whether there is finally a built-in that does that, my guess is no, and so this example is using arrow.m from the FEX http://www.mathworks.com/matlabcentral/fileexchange/278-arrow-m but there are many options, arrow3.m http://www.mathworks.com/matlabcentral/fileexchange/14056-arrow3-version-5 e.g. is a little fancier looking.
stp = 10; % Assuming by 'evenly spaced' you refer to the indices and not
% actual Euclidean distance
plot3(O(:,1),O(:,2),O(:,3)); % Plot the cont. line of origins
axis equal; hold on; % to make it nicer looking
set(gca,'XLim',get(gca,'XLim')+[-1 1]) % Make space for the arrows
set(gca,'YLim',get(gca,'YLim')+[-1 1])
set(gca,'ZLim',get(gca,'ZLim')+[-1 1])
plot3(O(1:stp:end,1),O(1:stp:end,2),O(1:stp:end,3),'o')
arrow([O(1:stp:end,:); O(1:stp:end,:); O(1:stp:end,:)],...
[X(1:stp:end,:); Y(1:stp:end,:); Z(1:stp:end,:)],'Length',15,'Width',2);
hold off
Note that you should do all the axis resizing before plotting the arrows, otherwise the arrows get resized, too, and then it'll look pretty ugly.

1 件のコメント

John Paul Donlon
John Paul Donlon 2012 年 11 月 16 日
Thank you, Jonathan; and from now on I will include sample data with my questions.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Line Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by