Question

I have a question relating to plotting a cylindrical surface in Matlab. My dataset consists of a point cloud of X, Y, Z coordinates with corresponding intensity values C.

I can plot them using the scatter3 function:

figure
scatter3(X,Y,Z,8,C)

results in the following image:

However, I would like to plot the surface of this object rather than the points. I have tried to achieve this using Delaunay triangulation

tri     = delaunay(X,Y);
figure
trisurf(tri,X,Y,Z,C,'FaceColor','interp')

Link to screenshots

As you can see from the image the result is not what I would like as there are difficulties with the triangulation. To me it seems as if the algorithm does not cope well with the fact that I get the same X and Y coordinates multiple times.

Following the examples introduced on the TriRep help page I have tried to use the following approach:

dt = DelaunayTri(X,Y,Z);
tr = TriRep(dt, X, Y, Z);

alas without success as I get the following error message when calling the TriRep function:

??? Error using ==> TriRep Parameter must be 'double matrix'.

I guess I have to constrain my geometry and I thought I found the solution in Example 1 here by using the freeBoundary function - though I do need the output of the TriRep function in order to calculate this. That's where I am stuck. As you can see I am no expert in triangulation methods and I would really appreciate any help you could offer. Thanks!

Was it helpful?

Solution

I think what you want is not a simple triangulation, but rather the convex hull of your set of points.

The classic analogy for a convex hull in 2d -
If you imagine your set of points to be nails on a board, then the convex hull is the polygon that would be formed by stretching a rubber band around your points - that is, it touches the external points but not the internal ones.

And extending this, you can think of the 3d convex hull as being a "skin" of the outside points in your point cloud.

The convex hull is the starting point for more complicated Computational Geometry techniques, but in your case will give you the mesh you are looking for.

I haven't used Matlab's version, but it looks pretty straightforward: http://www.mathworks.com/help/techdoc/ref/convhulln.html

Edit: After seeing your comments below: If you are already using a TriRep structure, you can use it to get the face normals, then delete any triangles whose face has a normal close to straight up/down. EG, if you start with the example from Matlab's FaceNormals doc page http://www.mathworks.com/help/techdoc/ref/trirep.facenormals.html :

numpts = 100;
thetha = rand(numpts,1)*2*pi;
phi = rand(numpts,1)*pi;
x = cos(thetha).*sin(phi);
y = sin(thetha).*sin(phi);
z = cos(phi);
dt = DelaunayTri(x,y,z);
[tri Xb] = freeBoundary(dt);
tr = TriRep(tri, Xb);
P = incenters(tr);
fn = faceNormals(tr);
trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3), 'FaceColor', 'cyan', 'faceAlpha', 0.8);

Then you can simply run through the normals, and remove any faces with a high z magnitude:

for(i=196:-1:1)
    if(abs(fn(i,3))>0.8)
        tri(i)=[];
    end
end
trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3),'FaceColor','red','faceAlpha',0.7);

HTH -- RC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top