surf関数で、新年の3Dグラフ表示をしてみました。
下記 bird_3d 関数を実行すると、ニワトリ風な物体が表示されます。
surf関数で複数の楕円体を表示しています。
---- bird_3d.m ----
function bird_3d
t = 0:0.05*pi:pi;
p = 0:0.05*pi:2*pi;
figure
%body
a=b=c=10
x = a*sin(t)'*cos(p);
y = b*sin(t)'*sin(p);
z = c*cos(t)'*ones(size(p));
surf(x,y,z)
xlabel('x'),ylabel('y'),zlabel('z')
hold on
%eyes
a=b=c=1
x = a*sin(t)'*cos(p);
y = b*sin(t)'*sin(p);
z = c*cos(t)'*ones(size(p));
surf(x+9,y+3,z+3)
surf(x+9,y-3,z+3)
%foot
a=8,b=2,c=1
x = a*sin(t)'*cos(p);
y = b*sin(t)'*sin(p);
z = c*cos(t)'*ones(size(p));
alpha=pi/8;
x_org=x; y_org=y;
y=cos(alpha)*y_org - sin(alpha)*x_org;
x=sin(alpha)*y_org + cos(alpha)*x_org;
surf(x+2,-y+4,z-9)
surf(x+2, y-4,z-9)
%crown
a=b=2,c=4;
x = a*sin(t)'*cos(p);
y = b*sin(t)'*sin(p);
z = c*cos(t)'*ones(size(p));
surf(x+2,y,z+9)
surf(x,y,z+10)
surf(x-2,y,z+9)
%bill
a=6,b=2,c=1
x = a*sin(t)'*cos(p);
y = b*sin(t)'*sin(p);
z = c*cos(t)'*ones(size(p));
surf(x+10,y,z)
surf(x+10,y,z-1)
%wings
t = 0:0.1*pi:pi;
p = 0:0.1*pi:2*pi;
a=4,b=8,c=1
x = a*sin(t)'*cos(p);
y = b*sin(t)'*sin(p);
z = c*cos(t)'*ones(size(p));
alpha=-pi/8;
y_org=y;z_org=z;
y=cos(alpha)*y_org - sin(alpha)*z_org;
z=sin(alpha)*y_org + cos(alpha)*z_org;
alpha=-pi/8;
x_org=x;z_org=z;
x=cos(alpha)*x_org - sin(alpha)*z_org;
z=sin(alpha)*x_org + cos(alpha)*z_org;
surf(x, y+8,z-1)
surf(x,-y-8,z-1)
endfunction
----
参考: