Matlab's patch function with interpolation produces different result based on order of vertices

喜欢而已 提交于 2019-12-24 07:39:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!