% sfariska_koordinater
set(0,'defaulttextinterpreter','latex')
clf
% [X Y Z]=meshgrid(-3:0.3:3);
% W=sqrt(X.^2+Y.^2+Z.^2);
% isosurface(X,Y,Z,W,2)
% axis equal
% grid
% alpha(0.3)
% hold on
v1=linspace(pi/3,pi/3+2*pi,30);
v2=linspace(0,pi,31);
[V1 V2]=meshgrid(v1,v2);
X=2*sin(V2).*cos(V1);
Y=2*sin(V2).*sin(V1);
Z=2*cos(V2);
surf(X,Y,Z,ones(size(X)))
alpha(0)
shading interp
axis equal
view([42,18])
%rotate3D on
hold on
xlabel('$x$','FontSize',14)
ylabel('$y$','FontSize',14)
zlabel('$z$','FontSize',14)
plot3([-2.5 2.5],[0 0 ], [ 0 0],'Color','black','LineWidth',2)
plot3([0 0 ],[-2.5 2.5], [ 0 0],'Color','black','LineWidth',2)
plot3([0 0 ], [ 0 0],[-2.5 2.5],'Color','black','LineWidth',2)
for n=1:29
    rp=2;
    v1p=v1(n);
    if v1p>2*pi
        v1p =v1p-2*pi;
    end
    v2p=pi/3;
    xp=rp*sin(v2p)*cos(v1p);
    yp=rp*sin(v2p)*sin(v1p);
    zp=rp*cos(v2p);
    title(['$\rho=$' num2str(rp) '$\ ,\ \theta =$' num2str(v1p) '$\ ,\ \phi =$' num2str(v2p)],'FontSize',14)
    %['\hspace*{-2  cm}$ D_vf(a,b)= $ ' num2str(-cos(t(n))/2+sin(t(n))/2)]
    linje=plot3([0 xp],[0 yp],[0 zp],'Color','black','LineWidth',0.5);
    radien=text(xp/2,yp/2,zp/2+0.1,'$\rho$','FontSize',14);
    punkt=plot3(xp,yp,zp,'*');
    linje2=plot3([xp xp],[yp yp],[0 zp],'Color','black','LineWidth',0.5);
    linje3=plot3([0 xp],[0 yp],[0 0],'Color','black','LineWidth',0.5);
    xp=0.45*sin(v2p/2)*cos(v1p);
    yp=0.45*sin(v2p/2)*sin(v1p);
    zp=0.45*cos(v2p/2);
    phi=text(xp,yp,zp,'$\phi$','FontSize',14);
    xp=0.45*cos(v1p/2);
    yp=0.45 *sin(v1p/2);
    zp=0;
    theta=text(xp,yp,0,'$\theta$','FontSize',14 );
    t=0:0.1:1;
    v2t=v2p*t;
    xp=0.4*sin(v2t)*cos(v1p);
    yp=0.4*sin(v2t)*sin(v1p);
    zp=0.4 *cos(v2t);
    vinkel2=plot3(xp,yp,zp);
    v2p=pi/3;
    v1t=v1p*t;
    xp=0.4*cos(v1t);
    yp=0.4*sin(v1t);
    % zp=0.4*cos(v2p).*ones(size(t));
    vinkel1=plot3(xp,yp,zeros(size(t)));
    if n==1
        pause
    else
        pause(0.5)
    end
    s=0:0.1:1;
    v1p=v1(n)*s+v1(n+1)*(1-s);
    xp=rp*sin(v2p)*cos(v1p);
    yp=rp*sin(v2p)*sin(v1p);
    zp=rp*cos(v2p)*ones(size(v1p));
    plot3(xp,yp,zp)
%     if n==29
%         pause
%     end
    delete(linje)
    delete(punkt)
    delete(vinkel2)
    delete(phi)
    delete(vinkel1) 
    delete(theta)
    delete(linje2)
    delete(linje3)
    delete(radien) 
end
v2=linspace(pi/3,5*pi/6,15);
for n=1:14
    rp=2;
    v2p=v2(n);
    v1p=v1(1);
    if v1p>2*pi
        v1p =v1p-2*pi;
    end
    v2p=v2(n);
    xp=rp*sin(v2p)*cos(v1p);
    yp=rp*sin(v2p)*sin(v1p);
    zp=rp*cos(v2p);
     title(['$\rho=$' num2str(rp) '$\ ,\ \theta =$' num2str(v1p) '$\ ,\ \phi =$' num2str(v2p)],'FontSize',14)
    linje=plot3([0 xp],[0 yp],[0 zp],'Color','black','LineWidth',0.5);
    radien=text(xp/2,yp/2,zp/2+0.1,'$\rho$','FontSize',14);
    punkt=plot3(xp,yp,zp,'*');
    linje2=plot3([xp xp],[yp yp],[0 zp],'Color','black','LineWidth',0.5);
    linje3=plot3([0 xp],[0 yp],[0 0],'Color','black','LineWidth',0.5);
    xp=0.45*sin(v2p/2)*cos(v1p);
    yp=0.45*sin(v2p/2)*sin(v1p);
    zp=0.45*cos(v2p/2);
    phi=text(xp,yp,zp,'$\phi$','FontSize',14);
    xp=0.45*cos(v1p/2);
    yp=0.45 *sin(v1p/2);
    zp=0;
    theta=text(xp,yp,0,'$\theta$','FontSize',14 );
    t=0:0.1:1;
    v2t=v2p*t;
    xp=0.4*sin(v2t)*cos(v1p);
    yp=0.4*sin(v2t)*sin(v1p);
    zp=0.4 *cos(v2t);
    vinkel2=plot3(xp,yp,zp);
    v2p=v2(n);
    v1t=v1p*t;
    xp=0.4*cos(v1t);
    yp=0.4*sin(v1t);
    % zp=0.4*cos(v2p).*ones(size(t));
    vinkel1=plot3(xp,yp,zeros(size(t)));
    if n==1
        pause
    else
        pause(0.1)
    end
    s=0:0.1:1;
    v2p=v2(n)*s+v2(n+1)*(1-s);
    xp=rp*sin(v2p)*cos(v1p);
    yp=rp*sin(v2p)*sin(v1p);
    zp=rp*cos(v2p)*ones(size(v1p));
    plot3(xp,yp,zp)
    if n<15
        delete(linje)
        delete(punkt)
        delete(vinkel2)
        delete(phi)
        delete(vinkel1) 
        delete(theta)
        delete(linje2)
        delete(linje3)
        delete(radien) 
    end
end
rp1=linspace(2,1,15);
for n=1:14
    rp=rp1(n);
    v2p=v2(15);
    v1p=v1(1);
    if v1p>2*pi
        v1p =v1p-2*pi;
    end
    %v2p=v2(n);
    xp=rp*sin(v2p)*cos(v1p);
    yp=rp*sin(v2p)*sin(v1p);
    zp=rp*cos(v2p);
     title(['$\rho=$' num2str(rp) '$\ ,\ \theta =$' num2str(v1p) '$\ ,\ \phi =$' num2str(v2p)],'FontSize',14)
    linje=plot3([0 xp],[0 yp],[0 zp],'Color','black','LineWidth',0.5);
    radien=text(xp/2,yp/2,zp/2+0.1,'$\rho$','FontSize',14);
    punkt=plot3(xp,yp,zp,'*');
    linje2=plot3([xp xp],[yp yp],[0 zp],'Color','black','LineWidth',0.5);
    linje3=plot3([0 xp],[0 yp],[0 0],'Color','black','LineWidth',0.5);
    xp=0.45*sin(v2p/2)*cos(v1p);
    yp=0.45*sin(v2p/2)*sin(v1p);
    zp=0.45*cos(v2p/2);
    phi=text(xp,yp,zp,'$\phi$','FontSize',14);
    xp=0.45*cos(v1p/2);
    yp=0.45 *sin(v1p/2);
    zp=0;
    theta=text(xp,yp,0,'$\theta$','FontSize',14 );
    t=0:0.1:1;
    v2t=v2p*t;
    xp=0.4*sin(v2t)*cos(v1p);
    yp=0.4*sin(v2t)*sin(v1p);
    zp=0.4 *cos(v2t);
    vinkel2=plot3(xp,yp,zp);
    v2p=v2(n);
    v1t=v1p*t;
    xp=0.4*cos(v1t);
    yp=0.4*sin(v1t);
    % zp=0.4*cos(v2p).*ones(size(t));
    vinkel1=plot3(xp,yp,zeros(size(t)));
    if n==1
        pause
    else
        pause(0.1)
    end
    s=0:0.1:1;
    rpp=rp1(n)*s+rp1(n+1)*(1-s);
    v2p=v2(15);
    v1p=v1(1);
    xp=rpp*sin(v2p)*cos(v1p);
    yp=rpp*sin(v2p)*sin(v1p);
    zp=rpp*cos(v2p)*ones(size(v1p));
    plot3(xp,yp,zp)
    delete(linje)
    delete(punkt)
    delete(vinkel2)
    delete(phi)
    delete(vinkel1) 
    delete(theta)
    delete(linje2)
    delete(linje3)
    delete(radien) 
%     if n==14
%         pause
%     end
end
v1=linspace(pi/3,pi/3-pi,30);
for n=1:29
    rp=1;
    v1p=v1(n);
    if v1p<0
        v1p =v1p+2*pi;
    end
    v2p=5*pi/6;
    xp=rp*sin(v2p)*cos(v1p);
    yp=rp*sin(v2p)*sin(v1p);
    zp=rp*cos(v2p);
     title(['$\rho=$' num2str(rp) '$\ ,\ \theta =$' num2str(v1p) '$\ ,\ \phi =$' num2str(v2p)],'FontSize',14)
    linje=plot3([0 xp],[0 yp],[0 zp],'Color','black','LineWidth',0.5);
    radien=text(xp/2,yp/2,zp/2+0.1,'$\rho$','FontSize',14);
    punkt=plot3(xp,yp,zp,'*');
    linje2=plot3([xp xp],[yp yp],[0 zp],'Color','black','LineWidth',0.5);
    linje3=plot3([0 xp],[0 yp],[0 0],'Color','black','LineWidth',0.5);
    xp=0.45*sin(v2p/2)*cos(v1p);
    yp=0.45*sin(v2p/2)*sin(v1p);
    zp=0.45*cos(v2p/2);
    phi=text(xp,yp,zp,'$\phi$','FontSize',14);
    xp=0.45*cos(v1p/2);
    yp=0.45 *sin(v1p/2);
    zp=0;
    theta=text(xp,yp,0,'$\theta$','FontSize',14 );
    t=0:0.1:1;
    v2t=v2p*t;
    xp=0.4*sin(v2t)*cos(v1p);
    yp=0.4*sin(v2t)*sin(v1p);
    zp=0.4 *cos(v2t);
    vinkel2=plot3(xp,yp,zp);
    v2p=5*pi/6;
    v1t=v1p*t;
    xp=0.4*cos(v1t);
    yp=0.4*sin(v1t);
    % zp=0.4*cos(v2p).*ones(size(t));
    vinkel1=plot3(xp,yp,zeros(size(t)));
    if n==1
        pause
    else
        pause(0.5)
    end
    s=0:0.1:1;
    v1p=v1(n)*s+v1(n+1)*(1-s);
    xp=rp*sin(v2p)*cos(v1p);
    yp=rp*sin(v2p)*sin(v1p);
    zp=rp*cos(v2p)*ones(size(v1p));
    plot3(xp,yp,zp)
%     if n==29
%         pause
%     end
    delete(linje)
    delete(punkt)
    delete(vinkel2)
    delete(phi)
    delete(vinkel1) 
    delete(theta)
    delete(linje2)
    delete(linje3)
    delete(radien) 
end
v2=linspace(5*pi/6,pi/6,15);
for n=1:14
    rp=1;
    v2p=v2(n);
    v1p=4*pi/3;
    if v1p>2*pi
        v1p =v1p-2*pi;
    end
    v2p=v2(n);
    xp=rp*sin(v2p)*cos(v1p);
    yp=rp*sin(v2p)*sin(v1p);
    zp=rp*cos(v2p);
     title(['$\rho=$' num2str(rp) '$\ ,\ \theta =$' num2str(v1p) '$\ ,\ \phi =$' num2str(v2p)],'FontSize',14)
    linje=plot3([0 xp],[0 yp],[0 zp],'Color','black','LineWidth',0.5);
    radien=text(xp/2,yp/2,zp/2+0.1,'$\rho$','FontSize',14);
    punkt=plot3(xp,yp,zp,'*');
    linje2=plot3([xp xp],[yp yp],[0 zp],'Color','black','LineWidth',0.5);
    linje3=plot3([0 xp],[0 yp],[0 0],'Color','black','LineWidth',0.5);
    xp=0.45*sin(v2p/2)*cos(v1p);
    yp=0.45*sin(v2p/2)*sin(v1p);
    zp=0.45*cos(v2p/2);
    phi=text(xp,yp,zp,'$\phi$','FontSize',14);
    xp=0.45*cos(v1p/2);
    yp=0.45 *sin(v1p/2);
    zp=0;
    theta=text(xp,yp,0,'$\theta$','FontSize',14 );
    t=0:0.1:1;
    v2t=v2p*t;
    xp=0.4*sin(v2t)*cos(v1p);
    yp=0.4*sin(v2t)*sin(v1p);
    zp=0.4 *cos(v2t);
    vinkel2=plot3(xp,yp,zp);
    v2p=v2(n);
    v1t=v1p*t;
    xp=0.4*cos(v1t);
    yp=0.4*sin(v1t);
    % zp=0.4*cos(v2p).*ones(size(t));
    vinkel1=plot3(xp,yp,zeros(size(t)));
    if n==1
        pause
    else
        pause(0.1)
    end
    if n<14
        s=0:0.1:1;
        v2p=v2(n)*s+v2(n+1)*(1-s);
        xp=rp*sin(v2p)*cos(v1p);
        yp=rp*sin(v2p)*sin(v1p);
        zp=rp*cos(v2p)*ones(size(v1p));
        plot3(xp,yp,zp)
    end
    if n<14
        delete(linje)
        delete(punkt)
        delete(vinkel2)
        delete(phi)
        delete(vinkel1) 
        delete(theta)
        delete(linje2)
        delete(linje3)
        delete(radien) 
    end
end

