function coil = incoil(rp) % Usage: COIL = incoil('rp'); % INCOIL is a program which facilitates coil design and % analysis. When invoked, a blank set of axes with a grid % is provided. The user interactively draws the coil on the % screen using the mouse to click on successive vertices of % the design. The program returns in COIL, a matrix which % can be used in subsequent coil analysis programs. % The single input argument is a string of either 'r' or 'p' % specifying whether a rectangular or polar grid is desired. % For information about the contents of COIL, type help BCOIL. % See Also OUTCOIL, RECOIL, BCOIL. % RJM 4/7/95 % Alicia & Roger's 1 year anniversary. % SET UP THE GRID SPACE hold off,clg if rp == 'p' polar(1,1),shg else plot(1,1),axis([-1 1 -1 1]),grid,shg end hold title('CLICK ON THIS DOT TO END INPUT --> O') % GET INPUT ANS DRAW x=0; y=0; n=0; flg=0; while flg==0, n=n+1; xold=x;,yold=y; [x,y]=ginput(1); if n>1, line([xold x],[yold y]) end rawcoil(n,:)=[x, y]; if (abs(x)>1 | abs(y)>1), flg=1; end end % NOW CONVERT rawcoil TO USEFUL INFORMATION % Each element is sotred as % (x,y) l theta % ===== = ======= % Midpoint length Angle of % of segment Current to % Horizontal [n,m]=size(rawcoil); for k=1:n-2, dx = (rawcoil(k+1,1)-rawcoil(k,1)); dy = (rawcoil(k+1,2)-rawcoil(k,2)); mx = (rawcoil(k+1,1)+rawcoil(k,1))/2; my = (rawcoil(k+1,2)+rawcoil(k,2))/2; l = (dx^2 + dy^2)^.5; if dx==0, theta=pi/2*sign(dy); else, theta = atan(dy/dx) + pi*(dx<0); end coil(k,:)=[mx my l theta]; end hold off