Animated line and vector plot is not appear in the same plot
3 views (last 30 days)
Show older comments
In the below mentioned code, i have a ball inside a bowl. ball and bowl are drawn using animatedline command.
I also want to plot vector between Q4 and FL1, a vaiable saved in the attched result file.
When i run this code the ball and the bowl disaapear.
Help me.
load('results.mat')
global rpi_CB_B rpi_CW_W
curve = animatedline('Color','b','LineWidth',1,'MarkerEdgeColor','b',...
'MarkerFaceColor','k',...
'MarkerSize',2);
curve1 = animatedline('Color',[0.5,0,0.5],'LineWidth',1,'MarkerEdgeColor','k',...
'MarkerFaceColor','k',...
'MarkerSize',2);
curve2 = animatedline('Color',[0.5,0,0.5],'LineWidth',1,'MarkerEdgeColor','k',...
'MarkerFaceColor','k',...
'MarkerSize',2);
curve3 = animatedline('Color',[0.5,0,0.5],'LineWidth',1,'MarkerEdgeColor','b',...
'MarkerFaceColor','b',...
'MarkerSize',2);
title('\bf {Position of the Ball within the Bowl}',...
'Interpreter','latex', 'fontsize', 10, 'fontname', 'times','fontweight', 'bold');
xlabel('$\bf{X ({\it m})}$','Interpreter','latex', 'fontsize', 12);
ylabel('$\bf{Y({\it m)}}$','Interpreter','latex', 'fontsize', 12);
grid on;
axis([-0.025 0.025 0 0.041]);
% view(3);
for i=1:length(t)
rCB_0_0 = x(i,34:36)';
rCW_0_0 = x(i,16:18)';
rP1_0_0 = x(i,43:45)';
LE = line([rCB_0_0(1,1) rP1_0_0(1,1)],[rCB_0_0(2,1) rP1_0_0(2,1)],[rCB_0_0(3,1) rP1_0_0(3,1)],'Color','red','LineStyle','-','LineWidth',2);
RW_0 = [x(i,1) x(i,2) x(i,3);...
x(i,4) x(i,5) x(i,6);...
x(i,7) x(i,8) x(i,9)]';
RB_0 = [x(i,19) x(i,20) x(i,21);...
x(i,22) x(i,23) x(i,24);...
x(i,25) x(i,26) x(i,27)]';
Q1 = rCB_0_0 + RB_0*rpi_CB_B(:,93);
S1 = rCW_0_0 + RW_0*rpi_CW_W(:,105);
L1 = line([Q1(1,1) S1(1,1)],[Q1(2,1) S1(2,1)],[Q1(3,1) S1(3,1)],'Color','red','LineStyle','-','LineWidth',2);
Q1 = rCB_0_0 + RB_0*rpi_CB_B(:,90);
S1 = rCW_0_0 + RW_0*rpi_CW_W(:,100);
L2 = line([Q1(1,1) S1(1,1)],[Q1(2,1) S1(2,1)],[Q1(3,1) S1(3,1)],'Color','red','LineStyle','-','LineWidth',2);
Q1 = rCB_0_0 + RB_0*rpi_CB_B(:,60);
S1 = rCW_0_0 + RW_0*rpi_CW_W(:,20);
L3 = line([Q1(1,1) S1(1,1)],[Q1(2,1) S1(2,1)],[Q1(3,1) S1(3,1)],'Color','red','LineStyle','-','LineWidth',2);
Q4 = rCB_0_0 + RB_0*rpi_CB_B(:,57);
S4 = rCW_0_0 + RW_0*rpi_CW_W(:,15);
L4 = line([Q4(1,1) S4(1,1)],[Q4(2,1) S4(2,1)],[Q4(3,1) S4(3,1)],'Color','red','LineStyle','-','LineWidth',2);
for j = 1:1:W
R2_0 = [x(i,1) x(i,2) x(i,3);...
x(i,4) x(i,5) x(i,6);...
x(i,7) x(i,8) x(i,9)]';
rpi1_0_0 = x(i,16:18)' + R2_0*(rpi_CW_W(:,j));
addpoints(curve1,rpi1_0_0(1,1),...
rpi1_0_0(2,1),...
rpi1_0_0(3,1));
end
drawnow;
clearpoints(curve)
for j = 1:1:B
RB_0 = [x(i,19) x(i,20) x(i,21);...
x(i,22) x(i,23) x(i,24);...
x(i,25) x(i,26) x(i,27)]';
rpi2_0_0 = x(i,34:36)' + RB_0*(rpi_CB_B(:,j));
addpoints(curve,rpi2_0_0(1,1),...
rpi2_0_0(2,1),...
rpi2_0_0(3,1));
end
drawnow;
addpoints(curve2,rP1_0_0(1,1),...
rP1_0_0(2,1),...
rP1_0_0(3,1));
drawnow;
delete(LE);
delete(L1);
delete(L2);
delete(L3);
delete(L4);
mm = 0.001;
%%%%%%% Vector plot
quiver3(Q4(1,1),Q4(2,1),Q4(3,1),...
FL4(1,i)*mm,FL4(2,i)*mm,FL4(3,i)*mm);
view(2)
% drawnow;
end
Answers (0)
See Also
Categories
Find more on Animation 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!