# fill3 command working strangely?

7 visualizaciones (últimos 30 días)
Jan Valdman el 6 de En. de 2016
Comentada: Mike Garrity el 14 de En. de 2016
I came accross a difference in the execution of fill3 command in the following code:
figure; subplot(1,2,1)
X=[0 1 1 0]'; Y=[0 0 1 1]'; Z=[0 0 0 1]';
fill3(X,Y,Z,Z); title('visualization error?')
subplot(1,2,2)
Z=[0 0 1 0]';
fill3(X,Y,Z,Z); title('visualization ok?')
This corresponds to the visualization of two fields with permuted vector of amplitudes on the same rectangle. It gives the following figure:
I would expect in both cases that faces and their colors are interpolated. Why is it not so in the left part? Can is be fixed somehow?
Thank you, Jan Valdman
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Mike Garrity el 6 de En. de 2016
I'm going to start with the geometry part of this and then come back to the colors.
The help for both patch and fill3 use the term "3D polygon". That's not really a meaningful term. Polygons are planar, so they're not really 3D. What they're trying to say is that the 2D plane the polygon is defined in can have any arbitrary orientation in 3D.
However, it doesn't generate an error if your coordinates are not planar. The reason is that it's not uncommon for roundoff errors to give you a set of points which are almost planar, but not quite. So patch projects the points onto a plane and triangulates the polygon there, ignoring the errors between the points and the projection plane.
But in the case you have here, the points aren't anywhere near being planar. There is no single well defined surface which goes through those four points. Perhaps the best choice would be to compute the minimal surface, but that would be extremely expensive. So in this case, we do the triangulation in the projection plane, even though the errors are extremely large.
When you have a boundary for a face which isn't even close to planar, then you need to mesh it to tell the graphics system what it's supposed to do in between those points.
The colors basically work the same way as the coordinates. The graphics hardware is going to do linear interpolation of the values to generate the colors, but there isn't a linear mapping which will span the four colors you've given here. So we just triangulate and perform linear interpolation within each of the triangular regions. The fix is the same. You need to subdivide the facet to tell the graphics system how you want to interpolate the colors, just as you do for the coordinates.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Mike Garrity el 14 de En. de 2016
I just posted a more detailed description of how this works on the MATLAB Graphics blog.

Iniciar sesión para comentar.

### Más respuestas (1)

Jan Valdman el 6 de En. de 2016
Editada: Jan Valdman el 6 de En. de 2016
Additinally, I also notice that replacing both commands
fill3(X,Y,Z,Z)
by
patch(X,Y,Z);
result in the same issue for the patch command:
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by