From octave-sources-request at bevo dot che dot wisc dot edu Fri May 28 04:22:01 1999 Subject: circlespace function From: Rolf Fabian To: "'octave-sources at bevo dot che dot wisc dot edu'" Date: Fri, 28 May 1999 11:25:47 +-200 ##USAGE circlespace( [ N{,M} ] {, CP, P } ) ## N equally spaced points on a unit - circle ## centered at origin of complex plane ## ## [ N,M ] vector first argument ( M>2 ) results in ## N*(M-1) equally spaced points on a polygon of ## unit-radius centered at origin of complex plane ## ( corner points are always included ) ## ##OPTIONS scalar ##M {=2} points per polygon side ## we get N*(M-1) different points because corners ## are considered only once ##CP={0} set flag to 'close' polygon i.e. add copy of ## first point at end, return N*(M-1)+1 data points ##P {=0} phase shift -pi .. pi real positive P ## invokes counter-clockwise rotation of all points ## ##NOTE * start is 1+0i on real positive axis (at P=0) ## * 'equally spaced' complex vector z means that ## abs(diff(z)) == CONST holds (as 'linspace') ##SEE ALSO linspace, logspace ##AUTHOR fabian at tu-cottbus dot de 990528 #EXA(a) NOTE set CP flag to close circles/polygons #CP=1; circle=circlespace(201,CP); polygon=circlespace([7,11],CP) #plot(circle,'+',polygon,'-*') #EXA(b) include phase shift #clg; hold on; CP=1; #for k=0:5 plot(circlespace([5,4],CP,k*pi/30),sprintf("- at %d%d",k,k)); end function y=circlespace( N, CP, P ) if (nargin<3) P =0; end if (nargin<2) CP=0; end if (nargin<1||any(N<2)) fprintf(stderr,"circlespace input error .. quit.\n"); y=[]; return end [nr,nc]=size(N); if (max(nr,nc)==1) M= 2; #scalar N else M=N(2); N=N(1); #vector end t= linspace(0,2*pi,N+1)'; #real parameter c= exp(i*(t+P)); #N+1 elements representing N corners #1st+last elements are identical if ( M>2 ) y=zeros(N*(M-1),1); #init COL, N sides * (M-1) points! j=1:(M-1); for k=1:N tmp=linspace(c(k),c(k+1),M).'; tmp(M)=[]; y(j+(k-1)*(M-1))=tmp; end if ( CP) y=[y;y(1)]; end else y = c; if (!CP) y(N+1)=[]; end #evenually rm 'closed loop' entry end endfunction