%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nel_micro =  6;  % number of microtubules (tension & compression)
nel_filam =  6;
nel_actin = 60;  % number of actin and intermediate filaments (tension)
node = 72;       % number of nodes
nel  = nel_micro + nel_filam + nel_actin; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% cell coordinates %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rad = 1.0;
nuc = 1/6;

K=[1/16*(10+2*sqrt(5)), 0, 0, 0;
    0, 1/3, 1, 0;
   -1, 1/3, 4, 0;
    1/3, 0, 0, 1];

F=[rad, rad, 0, rad]';

dof = K\F;

a=sqrt(dof(1)); 
b=sqrt(dof(2)); 
g=sqrt(dof(3)); 
h=sqrt(dof(4));

fac1=sqrt(3)/3;
fac2=sqrt(3)/6;

% coordinates of membrane
q0=[   0; +fac1*a; -h; 
    -a/2; -fac2*a; -h; 
    +a/2; -fac2*a; -h; 
	   0; -fac1*b; -g; 
    +b/2; +fac2*b; -g; 
    -b/2; +fac2*b; -g; 
       0; +fac1*b; +g; 
    -b/2; -fac2*b; +g; 
    +b/2; -fac2*b; +g;
	   0; -fac1*a; +h; 
	+a/2; +fac2*a; +h; 
    -a/2; +fac2*a; +h];
	
% coordinates of nucleus	
q0(37:72)=q0(1:36)*nuc;	
%%% cell coordinates %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% cell elements %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% microtubules
el( 1,:) = [  1  9 ];
el( 2,:) = [  2  7 ];
el( 3,:) = [  3  8 ];
el( 4,:) = [  4 11 ];
el( 5,:) = [  5 12 ];
el( 6,:) = [  6 10 ];

% intremediate filaments 
el( 7,:) = [  1  2 ];
el( 8,:) = [  2  3 ];
el( 9,:) = [  3  1 ];
el(10,:) = [ 10 11 ];
el(11,:) = [ 11 12 ];
el(12,:) = [ 12 10 ];

el(13,:) = [  1  5 ];
el(14,:) = [  2  6 ];
el(15,:) = [  3  4 ];
el(16,:) = [ 10  8 ];
el(17,:) = [ 11  9 ];
el(18,:) = [ 12  7 ];

el(19,:) = [  1  7 ];
el(20,:) = [  2  8 ];
el(21,:) = [  3  9 ];
el(22,:) = [ 10  4 ];
el(23,:) = [ 11  5 ];
el(24,:) = [ 12  6 ];

el(25,:) = [  4  9 ];
el(26,:) = [  9  5 ];
el(27,:) = [  5  7 ];
el(28,:) = [  7  6 ];
el(29,:) = [  6  8 ];
el(30,:) = [  8  4 ];

el(31:42,:) = [ (1:12)' (13:24)' ];
el(43:72,:) = [ el(1:30,1)+12  el(1:30,2)+12 ];

%%% cell elements %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% plot cell  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:nel
 edof(i,1)=i;
 for j=1:2
  ic1=3*j-1; ic2=3*j; ic3=3*j+1;
  edof(i,ic1)=el(i,j)*3-2;
  edof(i,ic2)=el(i,j)*3-1;
  edof(i,ic3)=el(i,j)*3;
 end
end

t=edof(:,2:7);
for i = 1:nel
    e_mat(i,1:6)=q0(t(i,:))';
end

figure(1); clf; set(gcf, 'renderer','zbuffer'); hold on; view(-12,16);

indx=[1;4];  X=e_mat(:,indx)';  Xc=[X; X(1,:)];
indx=[2;5];  Y=e_mat(:,indx)';  Yc=[Y; Y(1,:)];
indx=[3;6];  Z=e_mat(:,indx)';  Zc=[Z; Z(1,:)]; 

%%% plot microtubules %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ie=1:nel_micro
  color=[ 1.0; 0.7; 0.0 ]; width=10; 
% color=[ 0.5; 0.5; 0.5 ]; width=10; 
  h=plot3(Xc(:,ie),Yc(:,ie),Zc(:,ie),'LineWidth',width,'Color',color);  
end
%%% plot filaments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ie=(nel_micro+1):(30)
  color=[ 0.0; 1.0; 0.0 ]; width= 5;  
% color=[ 0.0; 0.0; 0.0 ]; width= 5;  
  h=plot3(Xc(:,ie),Yc(:,ie),Zc(:,ie),'LineWidth',width,'Color',color);  
end
%%% plot filaments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ie=(31):(nel_micro+36)
  color=[ 1.0; 0.7; 0.0 ]; width= 5;  
% color=[ 0.0; 0.0; 0.0 ]; width= 5;  
  h=plot3(Xc(:,ie),Yc(:,ie),Zc(:,ie),'LineWidth',width,'Color',color);  
end
%%% plot nucleus %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ie=(37+nel_filam+1):nel
  color=[ 1.0; 0.3; 1.0 ]; width= 5;  
% color=[ 0.0; 0.0; 0.0 ]; width= 5;  
  h=plot3(Xc(:,ie),Yc(:,ie),Zc(:,ie),'LineWidth',width,'Color',color);  
end

axis off; axis image;		
print('-depsc', '-r200',  ['cell04']);	
hold off
%%% plot cell  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
