九重塔

cylinderという関数を使って九重塔を書いてみました。

Contents

関数pagoda.mの作成

以下の関数を作成しました。 第1引数は層の数、第2引数は1階の形状です。

type pagoda.m
function pagoda(story,polygon)
% N storied pagoda
% story 層の数
% 1階の形状
if nargin<2;polygon=4;end;
if nargin<1;story=9;end;
set(gcf,'renderer','zbuffer','color',[1,1,1]);
% 心柱
[x,y,z]=cylinder([1,1],16);
z=z*(story*1.5);
r=0.1;
h=surf(x*r,y*r,z);
set(h,'facecolor',[1,1,0]*0.7,'edgecolor','none');hold on;
% 1階ずつ作成
t1=1.5*[1,1];
t2=fliplr(linspace(sqrt(r),sqrt(3),20)).^2;
X=[1;2];
Y=1:1/3:(polygon+1);
for n=0:(story-1)
    % 白壁
    [x,y,z]=cylinder(t1*0.95^n,polygon);
    z=z+n;
    if n==0;z(1,:)=-0.5;end;
    h=surf(x,y,z);
    set(h,'facecolor',[1,1,1]);
    % 朱柱
    x=interp2(x,Y,X);
    y=interp2(y,Y,X);
    z=interp2(z,Y,X);
    plot3(x,y,z,'r','linewidth',3);  
    % 屋根
    [x,y,z]=cylinder(t2*0.95^n,polygon);
    z=z*1.5+n+0.5;
    h=surf(x,y,z);
    set(h,'facecolor',[0.5,0.5,0.5]);
end;

% 相輪
zmax=max(z(:));
r=0.3;
[x,y,z]=cylinder([1,1],32);
x=x*r;
y=y*r;
zz=linspace(zmax,1.35*story,31);
for n=1:9;
    z(1,:)=zz(3*n-2);
    z(2,:)=zz(3*n);
    h=surf(x,y,z);
    set(h,'facecolor',[1,1,0]*0.8,'edgecolor','none');
end;

% 水煙
[x,y,z]=cylinder((2:-0.1:0).^0.25,polygon*2);
x(:,1:2:end)=0;
y(:,1:2:end)=0;
zz=linspace(1.34,1.4,size(z,1))*story;
z=zz'*ones(1,size(x,2));
h=surf(x*r,y*r,z);
set(h,'facecolor',[1,1,0]*0.8,'edgecolor','none');

% 珠
[x,y,z]=sphere;
r=0.15;
x=x*r;y=y*r;z=z*r;
for n=0:1
    h=surf(x,y,z+story*(1.42+n*0.08));
    set(h,'facecolor',[1,1,0]*0.8,'edgecolor','none');
end;
daspect([1,1,1]);
axis tight;axis off;
rotate3d on;

七重塔

figure;
pagoda(7,4);
view([10,10]);

九重塔

cla;
pagoda(9,4);
view([10,10]);

八角九重塔

cla;
pagoda(9,8);
view([10,10]);