clear all
close all

% disegna toro
[t,phi]=meshgrid(linspace(0,2*pi,20),linspace(0,2*pi,20));
gx=cos(t);
gy=sin(t);
gz(1:20,1:20)=0;
nx=-cos(t);
ny=-sin(t);
nz=gz;
bx=gz;
by=gz;
bz(1:20,1:20)=1;
rho=0.8;
x=gx+rho*cos(phi).*nx+rho*sin(phi).*bx;
y=gy+rho*cos(phi).*ny+rho*sin(phi).*by;
z=gz+rho*cos(phi).*nz+rho*sin(phi).*bz;
surf(x,y,z)
axis equal

figure
clear all

% disegna tubo con sezione ellittica attorno ad elica
[s,phi]=meshgrid(linspace(0,6*pi,40),linspace(0,2*pi,20));
s2=s/sqrt(2);
gx=cos(s2);
gy=sin(s2);
gz=s2;
nx=-cos(s2);
ny=-sin(s2);
nz(1:20,1:40)=0;
bx=sin(s2)/sqrt(2);
by=-cos(s2)/sqrt(2);
bz(1:20,1:40)=1/sqrt(2);
rho=0.8;
x=gx+rho*cos(phi).*nx+rho*sin(phi).*bx;
y=gy+rho*cos(phi).*ny+rho*sin(phi).*by;
z=gz+rho*cos(phi).*nz+rho*sin(phi).*bz;
surf(x,y,z)
axis tight
axis equal

figure
clear all

% disegna tubo con sezione ellittica attorno ad elica
[s,phi]=meshgrid(linspace(0,6*pi,40),linspace(0,2*pi,20));
s2=s/sqrt(2);
gx=cos(s2);
gy=sin(s2);
gz=s2;
nx=-cos(s2);
ny=-sin(s2);
nz(1:20,1:40)=0;
bx=sin(s2)/sqrt(2);
by=-cos(s2)/sqrt(2);
bz(1:20,1:40)=1/sqrt(2);
rho1=0.8;
rho2=0.3;
x=gx+rho1*cos(phi).*nx+rho2*sin(phi).*bx;
y=gy+rho1*cos(phi).*ny+rho2*sin(phi).*by;
z=gz+rho1*cos(phi).*nz+rho2*sin(phi).*bz;
surf(x,y,z)
axis tight
axis equal

figure
clear all

% disegna nastro di Moebius
[t,s]=meshgrid(linspace(0,2*pi,30),linspace(-0.3,0.3,8));
gx=cos(t);
gy=sin(t);
gz(1:8,1:30)=0;
nx=-cos(t);
ny=-sin(t);
nz=gz;
bx=gz;
by=gz;
bz(1:8,1:30)=1;
x=gx+s.*cos(t/2).*bx+s.*sin(t/2).*nx;
y=gy+s.*cos(t/2).*by+s.*sin(t/2).*ny;
z=gz+s.*cos(t/2).*bz+s.*sin(t/2).*nz;
surf(x,y,z)
axis equal

figure
clear all

% disegna punto sella
[x,y]=meshgrid(linspace(-1.5,1.5,20),linspace(-1.5,1.5,20));
z=y.^2-x.^2;
surf(x,y,z)

