%set parameters:
aminor = 1; % Torus minor radius, 1 is a good value, keep it less than Rmajor
Rmajor = 3; % Torus major radius, any number greater than aminor
numCycles = 12; %whole number, number of complete cycles in total
plotTorusSurface = 1; %1=plot surface and curve, 0=plot curve only

% plot 3D torus surface:
if plotTorusSurface==1;
    theta  = linspace(-pi, pi, 64)   ; % Poloidal angle
    phi    = linspace(0., 2*pi, 64) ; % Toroidal angle
    [t, p] = meshgrid(phi, theta);
    x = (Rmajor + aminor.*cos(p)) .* cos(t);
    y = (Rmajor + aminor.*cos(p)) .* sin(t);
    z = aminor.*sin(p);
    surf(x, y, z);    
    hold on;
end



%Plot the toroidal spiral parametric curve:
t=0:0.001:2*pi;
x=(Rmajor+aminor*cos(numCycles*t)).*cos(t);
y=(Rmajor+aminor*cos(numCycles*t)).*sin(t);
z=sin(numCycles*t);
plot3(x,y,z,'LineWidth',4,'Color',[0 0 0]);
pbaspect([(Rmajor+1)*2 (Rmajor+1)*2 aminor+1]);
hold off;