Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Patch circle by a color gradient

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)

enter image description here

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
like image 330
jarhead Avatar asked Jun 25 '26 03:06

jarhead


1 Answers

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

enter image description here

like image 91
Anthony Avatar answered Jun 27 '26 15:06

Anthony