classdef nma_spring %static class to make spring for plotting animations %by Nasser M. Abbasi properties end methods(Static) %--------------------------- % %--------------------------- function [x,y] = make(r,theta,N) %r: total length of spring %theta: in radians, anticlock wise is positive, % theta zero is position x-axis %N: number of twists in spring % %OUTPUT: % x,y coordinates of line to use to plot spring len = (4/6)*r; p = zeros(N,2); delr = len/N; r0 = (1/6)*r; p(2,1) = r0; p(2,2) = theta; for n=3:N-2 p(n,1)=r0+delr*n; z=atan(2*delr/p(n,1)); p(n,2)=theta+(-1)^n*z; end p(end-1,1)=(5/6)*r; p(end-1,2)=theta; p(end,1)=r; p(end,2)=theta; [x,y] = pol2cart(p(:,2),p(:,1)); end %---------------------------------------- function [x,y] = makeBox(w,h) x = zeros(5,1); y = zeros(5,1); x(1)= w/2; y(1)=0; x(2)= w/2; y(2)=h/2; x(3)= -w/2; y(3)=h/2; x(4)=-w/2; y(4)=0; x(5)=x(1); y(5)=y(1); end %--------------------------- % %--------------------------- function [x,y] = makeV2(len,N,w) %len: total length of spring %N: number of twists in spring % %OUTPUT: % x,y coordinates of line to use to plot spring nCoordinates = 2*N+4; p = zeros(nCoordinates,2); h = (1/6)*len; del=(len-2*h)/(N+1); done = false; n = 1; while not(done) if n==1 p(1,1)=0; p(1,2)=0; n = n + 1; elseif n==2 p(2,1)=0; p(2,2)=h; n = n + 1; elseif n