蒙特卡洛法求机器人工作空间,请问要如何修改程序,画出蓝色空间点云的图,而不是红色的线图?

如下图所示:
想要蓝色图的效果

img


下面的程序运行出来是红色的线条,应该如何修改?

img

程序如下:


clear;clc
%定义D-H参数
a1=0.3;
a2=0.89;
a3=0.15;
d1=0.68;
d4=1.02;
%定义XYZ的坐标值
for i=1:10000
  theta1=-(11/12)*pi+(11/6)*pi*rand;
  theta2=-(1/2)*pi+(8/9)*pi*rand;
  theta3=-(1/3)*pi+(2/3)*pi*rand; 
  theta4=-(10/9)*pi+(20/9)*pi*rand;
  theta5=-(2/3)*pi+(4/3)*pi*rand;
  theta6=-2*pi+4*pi*rand; 
  x(i)=cos(theta1)*(a1 + a3*cos(theta2 + theta3) - d4*sin(theta2 + theta3) + a2*cos(theta2));
  y(i)=sin(theta1)*(a1 + a3*cos(theta2 + theta3) - d4*sin(theta2 + theta3) + a2*cos(theta2));
  z(i)= d1 - d4*cos(theta2 + theta3) - a3*sin(theta2 + theta3) - a2*sin(theta2);
end
figure(1);clf
plot3(x,y,z,'r','MarkerSize',0.5);hold on
xlabel('x-axis/m'),ylabel('y-axis/m'),zlabel('z-axis/m');
title('机器人三维工作空间');
figure(2);clf
plot3(x,y,z,'r','MarkerSize',0.5);
view(0,90);hold on%俯视图
xlabel('x-axis/m'),ylabel('y-axis/m');
title('机器人XY平面工作空间投影');

只把plot3改成scatter3是不行的,还要改其它一些细节

img

 
clear;clc
%定义D-H参数
a1=0.3;
a2=0.89;
a3=0.15;
d1=0.68;
d4=1.02;
%定义XYZ的坐标值
for i=1:10000
  theta1=-(11/12)*pi+(11/6)*pi*rand;
  theta2=-(1/2)*pi+(8/9)*pi*rand;
  theta3=-(1/3)*pi+(2/3)*pi*rand; 
  theta4=-(10/9)*pi+(20/9)*pi*rand;
  theta5=-(2/3)*pi+(4/3)*pi*rand;
  theta6=-2*pi+4*pi*rand; 
  x(i)=cos(theta1)*(a1 + a3*cos(theta2 + theta3) - d4*sin(theta2 + theta3) + a2*cos(theta2));
  y(i)=sin(theta1)*(a1 + a3*cos(theta2 + theta3) - d4*sin(theta2 + theta3) + a2*cos(theta2));
  z(i)= d1 - d4*cos(theta2 + theta3) - a3*sin(theta2 + theta3) - a2*sin(theta2);
end
figure(1);clf
scatter3(x,y,z,1,'r','filled');
xlabel('x-axis/m'),ylabel('y-axis/m'),zlabel('z-axis/m');
title('机器人三维工作空间');
figure(2);clf
scatter3(x,y,z,1,'r','filled');
view(0,90);%俯视图
xlabel('x-axis/m'),ylabel('y-axis/m');
title('机器人XY平面工作空间投影');

只需要使用scatter3即可.....

figure(1);clf
plot3(x,y,z,'b','MarkerSize',0.5);hold on
xlabel('x-axis/m'),ylabel('y-axis/m'),zlabel('z-axis/m');
title('机器人三维工作空间');
figure(2);clf
scatter3(x,y,z,1,'b');
view(0,90);hold on%俯视图
xlabel('x-axis/m'),ylabel('y-axis/m');
title('机器人XY平面工作空间投影');

img

用scatter3函数
https://ww2.mathworks.cn/help/matlab/ref/scatter3.html

绘制部分不要用plot3,plot3是用于绘制多维折线图的
换成plt.scatter函数绘制即可
参考:https://matplotlib.org/stable/gallery/mplot3d/scatter3d.html

https://ask.csdn.net/questions/269923?spm=1005.2026.3001.5635&utm_medium=distribute.pc_relevant_ask_down.none-task-ask-2~default~OPENSEARCH~Rate-8.pc_feed_download_top3ask&depth_1-utm_source=distribute.pc_relevant_ask_down.none-task-ask-2~default~OPENSEARCH~Rate-8.pc_feed_download_top3ask