gpt4 book ai didi

matlab - 通过颜色渐变修补圆圈

转载 作者:太空宇宙 更新时间:2023-11-03 20:19:43 26 4
gpt4 key购买 nike

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

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

enter image description here

这是代码

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

enter image description here

关于matlab - 通过颜色渐变修补圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55615706/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com