Matlab Delaunay Triangle Point Cloud - color matrix

I would like to create a 3D surface graph that covers all points from a point cloud [X,Y,Z]. For example, this is a scatter plot of my cloud cloud:

scatter3(X,Y,Z,5,C)

Scatter plot

As you can see, each data point has an intensity value C.

I am now triangulating

dt      = DelaunayTri(X,Y,Z); 
[tri Xb]= freeBoundary(dt); 

And I get a triangulated surface

figure 
trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3), 'FaceColor', 'cyan', 'faceAlpha', 0.8);

Surface

However, when I try to set the surface color using

trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3),C,'EdgeAlpha',0,'FaceColor','interp')

I get an error: "Warning: color data is not set for interpolated shading" due to the fact that the size Cdoes not match Xbor tri.

How can I get the correct interpolated surface color?

+5
1

, 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');
+4

All Articles