clc
clear
close all
n=80;
t=pi/n;
x_max=1;
y_max=1;
z_max=1;
r_max=4;
num=12;
factor=6.4/num;
xi = -x_max/2:t:x_max/2;
yi = -y_max/2:t:y_max/2;
zi = -z_max/2:t:z_max/2;
[x,y,z] = meshgrid(xi,yi,zi);
F=cos(2.*pi.*x)+cos(2.*pi.*y)+cos(2.*pi.*z);
[fs,v]=isosurface(x,y,z,F,0);
v(:,2)=v(:,2)+r_max;
[~,rho] = cart2pol(v(:,1),v(:,2));
theta=v(:,1).*factor;
[v(:,1),v(:,2)] = pol2cart(theta,rho);
[fc,v2,c] = isocaps(x,y,z,F,0);
v2(:,2)=v2(:,2)+r_max;
[~,rho] = cart2pol(v2(:,1),v2(:,2));
theta=v2(:,1).*factor;
[v2(:,1),v2(:,2)] = pol2cart(theta,rho);
fn = [fs ; fc+length(v(:,1))];
vn = [v ; v2];
fges=fn;
vges=vn;
for i=1:Zellanzahl-1
phi=(i*2*pi)/(num);
R=[cos(phi) -sin(phi) 0;sin(phi) cos(phi) 0;0 0 1];
for j=1:length(vn(:,1))
viteration(j,:)=R*vn(j,:)';
end
fiteration = fn+i*max(max(fn));
fges = [fges ; fiteration];
vges = [vges ; viteration];
end
stlwrite('geometry.stl',fges,vges);