Home > matutils > circle.m

circle

PURPOSE ^

[x,y]=circle(x0,y0,r,npts,flag)

SYNOPSIS ^

function [x,y]=circle(x0,y0,r,npts,uflag)

DESCRIPTION ^

 [x,y]=circle(x0,y0,r,npts,flag)

 Generate points on circles of radius r
 centered at x0,y0
 npts arg optional - default 50
 if flag==1 the first point of each circle is
 duplicated as the last (useful for plotting).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [x,y]=circle(x0,y0,r,npts,uflag)
0002 % [x,y]=circle(x0,y0,r,npts,flag)
0003 %
0004 % Generate points on circles of radius r
0005 % centered at x0,y0
0006 % npts arg optional - default 50
0007 % if flag==1 the first point of each circle is
0008 % duplicated as the last (useful for plotting).
0009 
0010 if(~exist('npts'))
0011   npts=[];
0012 end
0013 
0014 if(~exist('uflag'))
0015   uflag=[];
0016 end
0017 
0018 if(isempty(npts))
0019   npts=50;
0020 end
0021 
0022 if(isempty(uflag))
0023   uflag=0;
0024 end
0025 
0026 if(all(size(r)==1))
0027   r=r*ones(size(x0));
0028 end
0029   
0030 
0031 % Make sure x0,y0,r are row vectors
0032 x0=x0(:)'; y0=y0(:)'; r=r(:)';
0033 
0034 % Make column vector of angles
0035 s=2*pi/npts; t=[0:s:2*pi-s]';
0036 
0037 % Make arrays of both
0038 x0=repmat(x0,size(t,1),1);
0039 y0=repmat(y0,size(t,1),1);
0040 r =repmat(r, size(t,1),1);
0041 t =repmat(t, 1,size(x0,2));
0042 
0043 [x,y]=pol2cart(t,r);
0044 x=x+x0;
0045 y=y+y0;
0046 
0047 % Close the circles if wanted
0048 if(uflag==1)
0049   x=[x;x(1,:)];
0050   y=[y;y(1,:)];
0051 end

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005