通过颜色渐变修补圆形 [英] Patch circle by a color gradient

查看:85
本文介绍了通过颜色渐变修补圆形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

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

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)

这是代码

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属性,以确保颜色填充垂直于轴的条纹(请参见

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

这篇关于通过颜色渐变修补圆形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆