Drawing circles with multi-colored patterns in the annulus
1 次查看(过去 30 天)
显示 更早的评论
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');


0 个评论
采纳的回答
KSSV
2016-8-9
编辑:KSSV
2016-8-9
clc; clear all ;
M = 10000 ;
N = M/4 ; % Four parts here
R1 = 0.5 ;% Radius of circle1
R2 = 1. ; % Radius of circle 2
th = linspace(0,2*pi,M) ; % Angle 0 to 360
% polar coordinates
x1 = R1*cos(th) ; y1 = R1*sin(th) ;
x2 = R2*cos(th) ; y2 = R2*sin(th) ;
%%Arrnage cooridnates into four parts
X1 = reshape(x1,[N,4])' ;
Y1 = reshape(y1,[N,4])' ;
X2 = fliplr(reshape(x2,[N,4])') ;
Y2 = fliplr(reshape(y2,[N,4])' );
% fill color
figure
hold on
for i = 1:4
if mod(i,2)
patch([X1(i,:) X2(i,:)],[Y1(i,:) Y2(i,:)],'r','edgecolor','none')
else
patch([X1(i,:) X2(i,:)],[Y1(i,:) Y2(i,:)],'b','edgecolor','none')
end
end
axis equal
0 个评论
更多回答(1 个)
Thorsten
2016-8-9
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!