您通过调用freeBoundary更改了绘制三角剖分中的点数:只留下曲面点,内部点不属于曲面.因此,您必须提取与这些点对应的C值.您可以使用’intersect(…,’rows’)’将曲面点Xb映射到原始点集XYZ上.基于此映射,您可以从C中提取所需的值.下面的代码执行此操作.
clear all;
XYZ = rand(100,3);
X=XYZ(:,1);
Y=XYZ(:,2);
Z=XYZ(:,3);
C=rand(size(X));
scatter3(X, Y, Z, 5,C);
dt = DelaunayTri(X, Y, Z);
[tri Xb]=freeBoundary(dt);
% map Xb onto XYZ
[~,IA,IB]=intersect(XYZ, Xb, 'rows');
% extract the needed colors using the IA map
Cn = C(IA);
% permute the surface triangulation points using IB map
Xbn = Xb(IB,:);
% map the point numbers used in triangle definitions
% NOTE: for that you need inverse map
iIB(IB) = 1:length(IB);
trin = iIB(tri);
trisurf(trin,Xbn(:,1),Xbn(:,2),Xbn(:,3),Cn,'EdgeAlpha',0,'FaceColor','interp');