# Math Help - 3D surface from data points in matlab

1. ## 3D surface from data points in matlab

I have a very large and dense 3D dataset that I'd like to render as a surface, but I keep getting the error message quoted below, which I don't really understand. Plotting the data points alone works fine though, and gives me

I'm using the following code to attempt to generate the surface, where x_ymin, z_ymin, and T_ymin are the three variables contained in the yminplane.mat file. I've also tried using "gridfit" (available from matlabcentral) instead of griddata, but to no avail.

Any help would be much appreciated!

Code:
load yminplane.mat

gx = x_ymin(1):min(x_ymin)/10:min(x_ymin);
gz = z_ymin(1):min(z_ymin)/10:min(z_ymin);

[XI,ZI] = meshgrid(gx,gz);
TI = griddata(x_ymin,z_ymin,T_ymin,XI,ZI);

surf(XI,ZI,TI), hold
plot3(x_ymin,z_ymin,T_ymin,'.')
Warning: Duplicate x-y data points detected: using average of the z values.
> In griddata at 83
In yminfig at 12
??? qhull precision warning:
The initial hull is narrow (cosine of min. angle is 1.0000000000000002).
A coplanar point may lead to a wide facet. Options 'QbB' (scale to unit box)
or 'Qbb' (scale last coordinate) may remove this warning. Use 'Pp' to skip
this warning. See 'Limitations' in qh-impre.htm.

qhull precision error: initial simplex is not convex. Distance=-6.1e-014

While executing: | qhull d Qt Qbb Qc

Options selected for Qhull 2003.1 2003/12/30:
delaunay Qtriangulate Qbbound-last Qcoplanar-keep _pre-merge
_zero-centrum Pgood Qinterior-keep _max-width 2.9e+002
Error-roundoff 4.1e-013 _one-merge 2.9e-012 Visible-distance 8.2e-013
U-coplanar-distance 8.2e-013 Width-outside 1.6e-012 _wide-facet 4.9e-012
_narrow-hull -2.2e-016

The input to qhull appears to be less than 3 dimensional, or a
computation has overflowed.

Qhull could not construct a clearly convex simplex from points:

The center point is coplanar with a facet, or a vertex is coplanar
with a neighboring facet. The maximum round off error for
computing distances is 4.1e-013. The center point, facets and distances
to the center point are as follows:

facet
p42
p4257
p0
distance= -2.6e-014

facet
p4299
p4257
p0
distance= -2.8e-014

facet
p4299
p42
p0
distance= -2.8e-014

facet
p4299
p42
p4257
distance= -2.8e-014

These points either have a maximum or minimum x-coordinate, or
they maximize the determinant for k coordinates. Trial points
are first selected from points that maximize a coordinate.

The min and max coordinates for each dimension are:

0: 3.84 295 difference= 291.2

1: 0 17 difference= 17

2: 6.939e-018 291.2 difference= 291.2

If the input should be full dimensional, you have several options that
may determine an initial simplex:
- use 'QJ' to joggle the input and make it full dimensional
- use 'QbB' to scale the points to the unit cube
- use 'QR0' to randomly rotate the input for different maximum points
- use 'Qs' to search all points for the initial simplex
- use 'En' to specify a maximum roundoff error less than 4.1e-013.
- trace execution with 'T3' to see the determinant for each point.

If the input is lower dimensional:
- use 'QJ' to joggle the input and make it full dimensional
- use 'Qbk:0Bk:0' to delete coordinate k from the input. You should
pick the coordinate with the least range. The hull will have the
correct topology.
- determine the flat containing the points, rotate the points
into a coordinate plane, and delete the other coordinates.
- add one or more points to make the input full dimensional.

This is a Delaunay triangulation and the input is co-circular or co-spherical:
- use 'Qz' to add a point "at infinity" (i.e., above the paraboloid)
- or use 'QJ' to joggle the input and avoid co-circular data

Error in ==> delaunayn at 81
t = qhullmx(x', 'd ', opt);

Error in ==> griddata>linear at 125
tri = delaunayn([x y]);

Error in ==> griddata at 98
zi = linear(x,y,z,xi,yi,opt);

Error in ==> yminfig at 12
TI = griddata(x_ymin,z_ymin,T_ymin,XI,ZI);

2. Try calling "unique" on the data first to remove any duplicate points and see if that helps. You may need to round the data to some degree in order to call unique.

Regards Elbarto

3. Calling "unique" solved the duplicates issue, but I still get the same qhull error. Any suggestions? Thanks!

4. Did you round your data off first before calling unique? My guess would be that there are some points that are close to being duplicated which are giving you some headaches. Try rounding to a few decimal places and see if that helps at all. You can always turn the warnings off by passing options to the function you are calling but its probably better that you hunt down the cause to avoid any unexpected behavior.

Regards Elbarto