function draw_circle(x,y,r,n)

% circle(X,Y,R) draws a circle (well, almost) centered at X,Y with radius R.
% circle(X,Y,R,N) uses 4N vertices in approximating a circle.
% 
% This function isn't efficient to use in a loop.  Instead, calculate Q and
% W outside of the loop and call line or patch inside.

if nargin<4, n=4; end

a = pi.*(0:(n-1))./(2*n);
sa = sin(a);
ca = cos(a);
q = [ca,-sa,-ca,sa,ca(1)];
w = [sa,ca,-sa,-ca,sa(1)];

% set(gca, 'DataAspectRatio',[1 1 1], 'Box','on')

%  line(x+r*q,y+r*w);
  patch(x+r*q,y+r*w,'k');
