问题
I have a patch with x,y,c coordinates as given below. Upon changing the order of points, MATLAB's patch
color interpolation changes.
x = [0.9000 1.0000 1.0000 0.9000]';
y = [0.5000 0.5000 0.6000 0.6000]';
c = [0.0278 0.0371 0.0325 0.0282]';
figure();
patch(x,y,c);
order = [2:4,1];
figure();
patch(x(order),y(order),c(order));
The above produces two different color patches. However, the coordinates and the color have only changed the sequence in cyclic manner. Any suggestions to overcome this?
回答1:
I think that this is because you're not closing your patch -- if the last point in your patch is not the same as the first point, MATLAB automatically closes it. Apparently this does something strange with the color interpolation. If you modify the code slightly so that your patch is closed, like so:
figure;
order = [1:4,1];
patch(x(order),y(order),c(order));
figure;
order = [2:4,1:2];
patch(x(order),y(order),c(order));
figure;
order = [3:4,1:3];
patch(x(order),y(order),c(order));
Then you get the same patch every time.
来源:https://stackoverflow.com/questions/58020419/matlabs-patch-function-with-interpolation-produces-different-result-based-on-or