annotate toolboxes/FullBNT-1.0.7/KPMtools/draw_circle.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function h = draw_circle(x, r, outline_color, fill_color)
wolffd@0 2 % draw filled circles at centers x with radii r.
wolffd@0 3 % x is a matrix of columns. r is a row vector.
wolffd@0 4
wolffd@0 5 n = 40; % resolution
wolffd@0 6 radians = [0:(2*pi)/(n-1):2*pi];
wolffd@0 7 unitC = [sin(radians); cos(radians)];
wolffd@0 8
wolffd@0 9 % extend r if necessary
wolffd@0 10 if length(r) < cols(x)
wolffd@0 11 r = [r repmat(r(length(r)), 1, cols(x)-length(r))];
wolffd@0 12 end
wolffd@0 13
wolffd@0 14 h = [];
wolffd@0 15 % hold is needed for fill()
wolffd@0 16 held = ishold;
wolffd@0 17 hold on
wolffd@0 18 for i=1:cols(x)
wolffd@0 19 y = unitC*r(i) + repmat(x(:, i), 1, n);
wolffd@0 20 if nargin < 4
wolffd@0 21 h = [h line(y(1,:), y(2,:), 'Color', outline_color)];
wolffd@0 22 else
wolffd@0 23 h = [h fill(y(1,:), y(2,:), fill_color, 'EdgeColor', outline_color)];
wolffd@0 24 end
wolffd@0 25 end
wolffd@0 26 if ~held
wolffd@0 27 hold off
wolffd@0 28 end