function draw_capsle(Electron_NEW_BS_CAPS, N, r, r2)
r= r*10;
r2 = r2*10;

Lsphere = length(Electron_NEW_BS_CAPS)-1;
L1 = 20;
N1 = randi(Lsphere,[N,1]);

j = 1;




%% 3D plot
% r =  300;
% r2 = 100;
a = [0,0,0,r];
a2 = [0,0,0,r2];



figure
for i = 1:N
    
    j = randi(length(Electron_NEW_BS_CAPS)-1);
    
    L2 = length(Electron_NEW_BS_CAPS(N1(i)).X);
    N2 = randi(L2,1);
    
    ind =  Electron_NEW_BS_CAPS(j).IndexDrawCAPS(N2,1);
    X = Electron_NEW_BS_CAPS(j).X(N2,1:ind);
    Y = Electron_NEW_BS_CAPS(j).Y(N2,1:ind);
    Z = Electron_NEW_BS_CAPS(j).Zcalc(N2,1:ind);
    Xn = Electron_NEW_BS_CAPS(j).Xn(N2,1);
    Yn = Electron_NEW_BS_CAPS(j).Yn(N2,1);
    Zn = Electron_NEW_BS_CAPS(j).Zn(N2,1);
    
    if isempty(Electron_NEW_BS_CAPS(j).XnC)
        
    else
        XnC = Electron_NEW_BS_CAPS(j).XnC(N2,1);
        YnC = Electron_NEW_BS_CAPS(j).YnC(N2,1);
        ZnC = Electron_NEW_BS_CAPS(j).ZnC(N2,1);
        Xn2C = Electron_NEW_BS_CAPS(j).Xn2C(N2,1);
        Yn2C = Electron_NEW_BS_CAPS(j).Yn2C(N2,1);
        Zn2C = Electron_NEW_BS_CAPS(j).Zn2C(N2,1);
        plot3(XnC,YnC,ZnC,'ro')
        plot3(Xn2C,Yn2C,Zn2C,'ro')
    end
    
    [x,y,z]=sphere;
    [x2,y2,z2] = sphere;
    
    % s1=surf(x*a(1,4)+a(1,1),y*a(1,4)+a(1,2),z*a(1,4)+a(1,3));
    % set(s1, 'FaceAlpha', 0.5);
    
    m1=mesh(x*a(1,4)+a(1,1),y*a(1,4)+a(1,2),z*a(1,4)+a(1,3));
    set(m1, 'FaceAlpha', 0.3);
    hold on
    m2=mesh(x2*a2(1,4)+a2(1,1),y2*a2(1,4)+a2(1,2),z2*a2(1,4)+a2(1,3));
    set(m2, 'FaceAlpha', 0.3);
    % plot3([0,X(3)],[0,Y(3)],[0,Z(3)],'r-*')
    plot3([Xn X],[Yn Y],[Zn Z],'k-+')
    plot3([Xn Xn],[Yn Yn],[r+round(r/3) Zn],'k--')
    
end
xlabel('X');ylabel('Y');zlabel('Z');

%% Draw MC_Capsle
% vykresleni simulace Capsle
figure;
viscircles([0,0],r); hold on; viscircles([0,0],r2);
for i = 1:N
L2 = length(Electron_NEW_BS_CAPS(N1(i)).X);
N2 = randi(L2,1);
j = randi(length(Electron_NEW_BS_CAPS)-1);

ind = Electron_NEW_BS_CAPS(j).IndexDrawCAPS(N2,1); %N1(i)

plot([Electron_NEW_BS_CAPS(j).Xn(N2,1),Electron_NEW_BS_CAPS(j).X(N2,1:ind)],[Electron_NEW_BS_CAPS(j).Zn(N2,1),Electron_NEW_BS_CAPS(j).Zcalc(N2,1:ind)],'b-*')
plot([Electron_NEW_BS_CAPS(j).Xn(N2,1),Electron_NEW_BS_CAPS(j).Xn(N2,1)],[r+round(r/3),Electron_NEW_BS_CAPS(j).Zn(N2,1)],'b--')


if isempty(Electron_NEW_BS_CAPS(j).XnC)
        
    else
        XnC = Electron_NEW_BS_CAPS(j).XnC(N2,1);
        ZnC = Electron_NEW_BS_CAPS(j).ZnC(N2,1);
        Xn2C = Electron_NEW_BS_CAPS(j).Xn2C(N2,1);
        Zn2C = Electron_NEW_BS_CAPS(j).Zn2C(N2,1);
        plot(XnC,ZnC,'ro')
        plot(Xn2C,Zn2C,'ro')
    end
    
% plot([Electron_NEW_BS(N1(i)).Xn(N2,1),  Electron_NEW_BS(N1(i)).X(N2,1:ind)],   [Electron_NEW_BS(N1(i)).Zn(N2,1),Electron_NEW_BS(N1(i)).Zcalc(N2,1:ind)],'b-*')
% plot([Electron_NEW_BS(N1(i)).Xn(N2,1),  Electron_NEW_BS(N1(i)).Xn(N2,1)],   [r+round(r/3),Electron_NEW_BS(N1(i)).Zn(N2,1)],'b--')
end
xlim([-2*r,2*r]);
ylim([-2*r,2*r]);
hold off
title('MC-Capsle')