fill3 command working strangely?

조회 수: 8 (최근 30일)
Jan Valdman
Jan Valdman 2016년 1월 6일
댓글: Mike Garrity 2016년 1월 14일
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

채택된 답변

Mike Garrity
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
Mike Garrity 2016년 1월 14일
I just posted a more detailed description of how this works on the MATLAB Graphics blog.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan Valdman
Jan Valdman 2016년 1월 6일
편집: Jan Valdman 2016년 1월 6일
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:

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by