Patch circle by a color gradient

蹲街弑〆低调 提交于 2020-01-04 01:08:28

问题


I'm attempting to plot a color gradient which I would like to be uniform along an axis (in the case of the picture below defined by the angle pi/7)

When I use the patch command, The plot matches the desired gradient direction, but is not uniform along it (all sorts of triangles are formed between the points along the circle)

here is the code

N=120;
theta = linspace(-pi,pi,N+1);
theta = theta(1:end-1);
c = exp(-6*cos(theta-pi/7));
figure(1)
patch(cos(theta),sin(theta),c)
ylabel('y'); xlabel('x')
axis equal

回答1:


You have to define the Facesproperty to make sure the colours fill stripes perpendicular to the axis (see Specifying Faces and Vertices) . Otherwise, MATLAB will use some algorithm to blend the colour as smoothly as it sees.

N=120;
a = pi/7;

theta = linspace(a,2*pi+a,N+1); % note that I changed the point sequence, this is just to make it easier to produce the matrix for Faces.
theta(end) = [];

ids = (1:N/2)';
faces = [ids, ids+1, N-ids, N-ids+1];

c = exp(-6*cos(a-theta))';

figure
patch('Faces', faces, 'Vertices',[cos(theta);sin(theta)]','FaceVertexCData',c, 'FaceColor', 'interp', 'EdgeColor', 'none')
ylabel('y'); xlabel('x')
axis equal



来源:https://stackoverflow.com/questions/55615706/patch-circle-by-a-color-gradient

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