Drawing circles with multi-colored patterns in the annulus
Afficher commentaires plus anciens
This code gives me a circle with a green center and red annulus. What's the simplest way to create patterns within the annulus, like those shown below in blue and yellow?
xpix = 912;
ypix = 1140;
rad = 200;
RGB = zeros(ypix,xpix,3,'uint8');
[x,y] = meshgrid(1:xpix,1:ypix);
xc = (xpix+1)/2;
yc = (ypix+1)/2;
r = sqrt((x-xc).^2+(y-yc).^2);
% Center
ii = r <= rad/1.5;
RGB(:,:,2)=255*ii;
% Annulus
ii = r <= rad & ~ii;
RGB(:,:,1)=255*ii;
imshow(RGB);
imwrite(RGB,'filter.bmp');


Réponse acceptée
Plus de réponses (1)
Thorsten
le 9 Août 2016
You can generate your circles using my function plot annulus
plotannulus(0, 0, 5, 10, [0 0 1; 1 1 0], deg2rad(90))
plotannulus(0, 0, 5, 10, repmat([0 0 1; 1 1 0], 2, 1), deg2rad(45))
plotannulus(0, 0, 5, 10, repmat([0 0 1; 1 1 0], 3, 1), deg2rad(60))
plotannulus(0, 0, 5, 10, repmat([0 0 1; 1 1 0], 4, 1), deg2rad(0))
The plotannulus function:
function h = plotannulus(cx, cy, r1, r2, col, theta0)
%PLOTANNULUS
%
% H = PLOTANNULUS(CX, CY, R1, R2, COL, [THETA0])
%
% THETA0 Start angle in radians of the first color, if more than one color
% for the annulus is given. Default is 0.
%
% Examples
% plotannulus(0, 0, 5, 10, repmat([0 0 1; 1 1 0], 2, 1), deg2rad(45))
% plotannulus(0, 0, 5, 10, parula(12))
% plotannulus(0, 0, 5, 10, jet)
if nargin < 5, col = [0.5 0.5 0.5]; end
if nargin < 6, theta0 = 0; end
Ncol = size(col, 1);
delta_theta = 2*pi/Ncol;
Theta = linspace(0, (2*pi - delta_theta), Ncol) + theta0;
Npoints = 360/Ncol; % number of points along the radii to approximate the
% circle
for i = 1:Ncol
theta = linspace(Theta(i), Theta(i)+delta_theta, Npoints);
x1 = r1*cos(theta);
y1 = r1*sin(theta);
x2 = r2*cos(theta);
y2 = r2*sin(theta);
h(i) = patch([x1 fliplr(x2)] + cx,...
[y1 fliplr(y2)] + cy,...
col(i,:), 'EdgeColor', col(i,:));
end
if nargout == 0
clear h
end
Catégories
En savoir plus sur Axes Transformations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!