Plotting trajectory from displacement/time history
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jonathan Epperl
2012-11-16
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Guidance, Navigation, and Control (GNC) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!