I am trying to visualize the rotation of a coordinate system from a fixed world frame to a rotated body frame. I rotated the frame using a DCM and now I am trying to animate the movement of the new frame (which is 3 orthogonal vectors) from the initial frame to its rotated orientation.
I want to use quiver3 but I cannot get the previous quiver to delete itself from the plot before the next one is drawn. The result is a procession of arrows slowly changing size and turning until they reach their final orientation.
I suspect it is an issue with hold on/ hold off though I do not know.
If anyone could help me create a smooth animation of the vectors rotating in space from their initial starting position to their final orientation I would be appreciative.
Thanks!
clear all;
k = [0; 0; 1;];
j = [0; 1; 0;];
i = [1; 0; 0;];
starts = zeros(3,3);
ends = [i j k];
t = linspace(0,1,100);
yaw = pi/4;
pitch = pi/4;
roll = pi/4;
quiver3(starts(1,:), starts(2,:), starts(3,:), ends(1,:), ends(2,:), ends(3,:))
hold on;
for k = 1:length(t)
hold on;
yawDCM = [cos(yaw*t(k)) sin(yaw*t(k)) 0; -sin(yaw*t(k)) cos(yaw*t(k)) 0; 0 0 1*t(k)];
pitchDCM = [cos(pitch*t(k)) 0 -sin(pitch*t(k)); 0 1*t(k) 0; sin(pitch*t(k)) 0 cos(pitch*t(k));];
rollDCM = [1*t(k) 0 0; 0 cos(roll*t(k)) sin(roll*t(k)); 0 -sin(roll*t(k)) cos(roll*t(k));];
Q = yawDCM*pitchDCM*rollDCM;
ends2 = Q*ends;
% hold on;
% plot3(ends2(1,1), ends2(1,2), ends2(1,3), '--');
% plot3(ends2(2,1), ends2(2,2), ends2(2,3), '--');
% plot3(ends2(3,1), ends2(3,2), ends2(3,3), '--');
% pause(.01);
% hold off;
quiver3(starts(:,1), starts(:,2), starts(:,3), ends2(:,1), ends2(:,2), ends2(:,3), 0);
pause(.1);
hold off
end
axis equal
question from:
https://stackoverflow.com/questions/66068914/how-do-i-animate-the-rotation-of-a-set-of-vectors-in-matlab