通过颜色渐变修补圆圈

Patch circle by a color gradient

我正在尝试绘制颜色渐变,我希望它沿轴均匀(在下图中由角度 pi/7 定义的图片的情况下)

当我使用patch命令时,绘图符合所需的梯度方向,但沿方向不均匀(沿圆的点之间形成各种三角形)

这是代码

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

您必须定义 Faces属性 以确保颜色填充垂直于轴的条纹(参见 Specifying Faces and Vertices)。否则,MATLAB 将使用某种算法来平滑地混合颜色。

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