fill3 command working strangely?
5 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153056/image.jpeg)
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 个评论
采纳的回答
Mike Garrity
2016-1-6
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 个评论
Mike Garrity
2016-1-14
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!