Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpolate surface of 3D cylinder in Matlab

I have a dataset that describes a point cloud of a 3D cylinder (xx,yy,zz,C): 3D point cloud

and I would like to make a surface plot from this dataset, similar to this enter image description here

In order to do this I thought I could interpolate my scattered data using TriScatteredInterp onto a regular grid and then plot it using surf:

F = TriScatteredInterp(xx,yy,zz);
max_x = max(xx); min_x = min(xx);
max_y = max(yy); min_y = min(yy);
max_z = max(zz); min_z = min(zz);
xi = min_x:abs(stepSize):max_x;
yi = min_y:abs(stepSize):max_y;
zi = min_z:abs(stepSize):max_z;
[qx,qy] = meshgrid(xi,yi);
qz = F(qx,qy);
F = TriScatteredInterp(xx,yy,C);
qc = F(qx,qy);

figure
surf(qx,qy,qz,qc);
axis image

This works really well for convex and concave objects but ends in this for the cylinder: enter image description here

Can anybody help me as to how to achieve a nicer plot?

like image 245
space-dementia Avatar asked Oct 12 '12 16:10

space-dementia


People also ask

How do you interpolate in 3d Matlab?

Vq = interp3( X,Y,Z , V , Xq,Yq,Zq ) returns interpolated values of a function of three variables at specific query points using linear interpolation. The results always pass through the original sampling of the function. X , Y , and Z contain the coordinates of the sample points.

How do you interpolate a surface in Matlab?

vq = griddata( x , y , v , xq , yq ) fits a surface of the form v = f(x,y) to the scattered data in the vectors (x,y,v) . The griddata function interpolates the surface at the query points specified by (xq,yq) and returns the interpolated values, vq .

Which Matlab function will be useful for interpolating a gridded data on some 3d surface?

Use griddedInterpolant to perform interpolation on a 1-D, 2-D, 3-D, or N-D gridded data set. griddedInterpolant returns the interpolant F for the given data set. You can evaluate F at a set of query points, such as (xq,yq) in 2-D, to produce interpolated values vq = F(xq,yq) .

How do you interpolate a surface?

The three basic methods used to create interpolated surfaces are spline, inverse distance weighting (IDW), and trend surface. The spline interpolation method forces a smoothed curve through the set of known input points to estimate the unknown, intervening values.


2 Answers

Have you tried Delaunay triangulation?

http://www.mathworks.com/help/matlab/ref/delaunay.html

load seamount
tri = delaunay(x,y);
trisurf(tri,x,y,z);

plot

There is also TriScatteredInterp

http://www.mathworks.com/help/matlab/ref/triscatteredinterp.html

ti = -2:.25:2;
[qx,qy] = meshgrid(ti,ti);
qz = F(qx,qy);
mesh(qx,qy,qz);
hold on;
plot3(x,y,z,'o');

enter image description here

like image 144
ccook Avatar answered Sep 29 '22 16:09

ccook


I think what you are loking for is the Convex hull function. See its documentation.

K = convhull(X,Y,Z) returns the 3-D convex hull of the points (X,Y,Z), where X, Y, and Z are column vectors. K is a triangulation representing the boundary of the convex hull. K is of size mtri-by-3, where mtri is the number of triangular facets. That is, each row of K is a triangle defined in terms of the point indices.

Example in 2D

xx = -1:.05:1; yy = abs(sqrt(xx));
[x,y] = pol2cart(xx,yy);
k = convhull(x,y);
plot(x(k),y(k),'r-',x,y,'b+')

enter image description here

Use plot to plot the output of convhull in 2-D. Use trisurf or trimesh to plot the output of convhull in 3-D.

like image 23
SamuelNLP Avatar answered Sep 29 '22 14:09

SamuelNLP