fill3 command working strangely?

6 views (last 30 days)
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

Accepted Answer

Mike Garrity
Mike Garrity on 6 Jan 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.

More Answers (1)

Jan Valdman
Jan Valdman on 6 Jan 2016
Edited: Jan Valdman on 6 Jan 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:

Community Treasure Hunt

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

Start Hunting!