Plotting trajectory from displacement/time history
9 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Jonathan Epperl
on 16 Nov 2012
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.
More Answers (0)
See Also
Categories
Find more on Geographic 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!