在处理三维数据的情况下,想画个空间的圆柱侧面,以至于下午琢磨了好久,也没搞明白cylinder是怎么用的,出去玩一会,回来就突然查到点什么资料,就给幸运的出来结果了,直接贴代码喽~~~欢迎交流哦
% FACE=pcread('1001_p.ply'); % pcshow(FACE); % hold on; face=load('1sub0.5.txt'); x=face(:,1);y=face(:,2);z=face(:,3); %设置分段 N = 400; xmin = min(x);xmax = max(x);dx=(xmax-xmin)/(N-1);x0=(xmin:dx:xmax); ymin = min(y);ymax = max(y);dy=(ymax-ymin)/(N-1);y0=[ymin:dy:ymax]; %生成网格采样点 [XI,YI] = meshgrid(x0,y0); %进行内插 ZI = griddata(x,y,z,XI,YI,'cubic'); % ZI = interp2(x,y,z,XI,YI,'cubic'); %设置光照 light('position',[0 0 1],'style','local'); lighting phong; %绘制三维人脸,然后按着鼠标旋转查看 surf(XI,YI,ZI);shading interp; %绘制圆柱体侧面 ind=find(z==max(z)); ox=face(ind,1);oy=face(ind,2);oz=face(ind,3); % plot3(x,y,z); hold on; [x,y,z]=cylinder(30); surf(x+ox,y+oy,60*z+oz-50,'FaceColor','black'); view(30,30); %设置图像显示角度 rotate3d on;
结果图就是上面酱紫嘞。