1、前言如题
2、参考连接如下
How to plot two moving robot in the same figure and change one of them transparency? - MATLAB Answers - MATLAB Central (mathworks.cn)3、代码:【找到figure中对应对象并设置属性】
% Create two instances of a rigid body tree since we want two visuals
rbt=loadrobot("kinovagen3",DataFormat="row");
copyrbt=copy(rbt);% Some random configurations
q0=homeConfiguration(rbt);
q1=randomConfiguration(rbt);
q2=randomConfiguration(rbt);% Generate a trajectory to the random configurations
tpts=[0,1];
tquery=tpts(1):0.01:tpts(end);
traj1=quinticpolytraj([q0',q1'],tpts,tquery)';
traj2=quinticpolytraj([q0',q2'],tpts,tquery)';% Find the patches which have a display name of '_mesh', and set their
% alpha values.
ax=show(rbt,traj1(1,:),PreservePlot=false,FastUpdate=true);
rbtpatches=findobj(ax.Children,'Type','patch','-regexp','DisplayName','_mesh');
set(rbtpatches,'FaceAlpha',0.2);% Now visualize another instance of the same robot
hold on;
show(copyrbt,traj2(1,:),PreservePlot=false,FastUpdate=true,Parent=ax);% This call will also find the previous patches. Hence we need to remove
% previously found patches from this query.
patchesnew=findobj(ax.Children,'Type','patch','-regexp','DisplayName','_mesh');
copyrbtpatches=patchesnew(~ismember(patchesnew,rbtpatches));% You can also change the color aside from alpha
set(copyrbtpatches,'FaceAlpha',0.7);
set(copyrbtpatches,'FaceColor',[1,0,0]);%% Visualize
rc=rateControl(50);
for i=1:size(tquery,2)show(rbt,traj1(i,:),PreservePlot=false,FastUpdate=true);show(copyrbt,traj2(i,:),PreservePlot=false,FastUpdate=true,Parent=ax);waitfor(rc);
end
hold off;
4、结果【同样的轨迹,实影的先运动几个步数,虚影后续运动】