home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / BUCKY.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  3.2 KB  |  149 lines

  1. function [Bout,Vout] = bucky
  2. %BUCKY    Connectivity graph of the Buckminister Fuller geodesic dome.
  3. %    B = BUCKY is the 60-by-60 sparse adjacency matrix of the
  4. %        connectivity graph of the geodesic dome, the soccer ball,
  5. %        and the carbon-60 molecule.
  6. %    [B,V] = BUCKY also returns xyz coordinates of the vertices.
  7. %
  8. %    BUCKY, with no output arguments, demonstrates itself.
  9.  
  10. %    C. B. Moler, 2-14-91, 10-8-91, 8-11-92.
  11. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  12.  
  13. % These all-important parameters were generated by numeric
  14. % search in another program.  I wish I had formulas for them.
  15.  
  16. alfa = [1.220391131161 0.814053008553 0.540911992917 0.172493462472];
  17. beta = [0.310919101124 0.164146934496];
  18.  
  19. % Northern hemisphere
  20. B = sparse(30,30);
  21. phi = zeros(30,1);
  22. theta = zeros(30,1);
  23. j = 0;
  24. k = 5;
  25. for t = 0:4
  26.    j = j+1;
  27.    phi(j) = alfa(1);
  28.    theta(j) = t*2*pi/5;
  29.    B(j,k+1) = 1;
  30.    B(j,rem(j,5)+1) = 1;
  31.  
  32.    k = k+1;
  33.    phi(k) = alfa(2);
  34.    theta(k) = t*2*pi/5;
  35.    B(k,k+1) = 1;
  36.    B(k,k+4) = 1;
  37.  
  38.    k = k+1;
  39.    phi(k) = alfa(3);
  40.    theta(k) = (t-beta(1))*2*pi/5;
  41.    B(k,k+1) = 1;
  42.  
  43.    k = k+1;
  44.    phi(k) = alfa(4);
  45.    theta(k) = (t-beta(2))*2*pi/5;
  46.    B(k,k+1) = 1;
  47.  
  48.    k = k+1;
  49.    phi(k) = alfa(4);
  50.    theta(k) = (t+beta(2))*2*pi/5;
  51.    B(k,k+1) = 1;
  52.  
  53.    k = k+1;
  54.    phi(k) = alfa(3);
  55.    theta(k) = (t+beta(1))*2*pi/5;
  56.    if k+2 < 30, B(k,k+2) = 1;
  57.    else B(k,7) = 1; end
  58. end
  59. B = B + B';
  60.  
  61. % Reflect into southern hemisphere
  62. k = 60:-1:31;
  63. phi(k) = -phi;
  64. theta(k) = pi+theta;
  65. B(k,k) = B;
  66.  
  67. % Connect the two hemispheres
  68. k = find(sum(B)==2);
  69. j = k(1:10);
  70. k = k([15:-1:11 20:-1:16]);
  71. c = sparse(j,k,ones(size(j)),60,60);
  72. B = B + c + c';
  73.  
  74. % Generate the 3-D coordinates
  75. x = cos(phi).*cos(theta);
  76. y = cos(phi).*sin(theta);
  77. z = sin(phi);
  78. V = [x y z];
  79.  
  80. if nargout == 2
  81.    Bout = B;
  82.    Vout = V;
  83. elseif nargout == 1
  84.    Bout = B;
  85. else
  86.    help bucky
  87.    disp(' ')
  88.    disp('Press any key to continue after pauses.')
  89.    disp('pause'), pause
  90.  
  91.    disp(' ')
  92.    disp('The entire graph, with no numbering specified.')
  93.    disp(' ')
  94.    H = sparse(60,60);
  95.    k = 31:60;
  96.    H(k,k) = B(k,k);
  97.    gplot(H,V,'m-')
  98.    axis('equal');
  99.    hold('on')
  100.    gplot(B-H,V,'c-');
  101.    hold('off')
  102.    disp('pause'), pause
  103.  
  104.    disp(' ')
  105.    disp('Number the nodes in one hemisphere, pentagon by pentagon.')
  106.    disp(' ')
  107.    gplot(B(1:30,1:30),[x(1:30) y(1:30)])
  108.    for j = 1:30
  109.       text(x(j),y(j),int2str(j));
  110.    end
  111.    axis('equal');
  112.    disp('pause'), pause
  113.  
  114.    disp(' ')
  115.    disp('''Spy'' plot of the resulting sparse matrix.')
  116.    disp(' ')
  117.    spy(B(1:30,1:30))
  118.    disp('pause'), pause
  119.  
  120.    disp(' ')
  121.    disp('Reflect numbering of one hemisphere into the other.')
  122.    disp(' ')
  123.    % Map northern hemisphere onto 0 <= r <= 1 
  124.    % and southern hemisphere onto 1 <= r <= s.
  125.    s = 1.65;
  126.    r = x.*x + y.*y;
  127.    k = find(z < 0);
  128.    x(k) = x(k)./r(k);
  129.    y(k) = y(k)./r(k);
  130.    r = sqrt(x.*x + y.*y);
  131.    r = min(s,r)./r;
  132.    x = r.*x;
  133.    y = r.*y;
  134.    gplot(B,[x y])
  135.    for j = 1:60
  136.       text(x(j),y(j),int2str(j));
  137.    end
  138.    axis('equal');
  139.    axis([-s s -s s]);
  140.    disp('pause'), pause
  141.  
  142.    disp(' ')
  143.    disp('''Spy'' plot of the final sparse matrix.')
  144.    disp(' ')
  145.    spy(B)
  146.  
  147.    disp('End')
  148. end
  149.