標籤:

如何用Matlab畫一朵花?

不同種的花~

相關問題:如何用python畫一朵花?


在其他地方回答過一個類似的:

如何用各學科專業知識高大上地表白? - 知乎用戶的回答

[x,t] = meshgrid((0:24)/24,(0:.5:575)/575*17*pi-2*pi);
p = (pi/2)*exp(-t/(8*pi));
u = 1-(1-mod(3.6*t,2*pi)/pi).^4/2;
y = 2*(x.^2-x).^2.*sin(p);
r = u.*(x.*sin(p)+y.*cos(p));
figure("color","w"),view(-22,66), axis image off
surface(r.*cos(t),r.*sin(t),u.*(x.*cos(p)-y.*sin(p)),"EdgeC","n","FaceC","r")
light("pos",[-.25 -.25 1], "style","local", "col",[1 0.84 0.6]),lighting gouraud

------------------補下心臟體的代碼(其中用到的 uniquetol 從2015a 才有)------------------

[X,Y,Z] = meshgrid(-1.2:.02:1.2,-3:.03:3,-1:.02:1.3);
f = smooth3((X.^2+9*Y.^2/9+Z.^2-1).^3-X.^2.*Z.^3-Y.^2.*Z.^3/10,"gauss");
v = uniquetol(getfield(isosurface(X,Y,Z,f,0),"vertices"),.15,"byrows",1);
n = isonormals(X,Y,Z,f,v);
ar = bsxfun(@rdivide,n*[0 -1 0;1 0 0;0 0 0],sqrt(sum(n.^2,2)));

[x,t] = meshgrid(0:.125:1,(-2:.2:10)*pi);
[p,q] = deal(pi/2*exp(-t/(8*pi)),1-(1-mod(3.6*t,2*pi)/pi).^4/2);
y = 2*(x.^2-x).^2.*sin(p);
[p,q] = deal(q.*(x.*sin(p)+y.*cos(p)),q.*(x.*cos(p)-y.*sin(p)));

figure color w, axis image vis3d off
h = surface(p.*cos(t),p.*sin(t),q,"EdgeColor","n","FaceColor","r");
arrayfun(@(t,i)copyobj(h,hgtransform("Mat",makehgtform("translate",5*v(i,:),...
"axisrotate",ar(i,:),t))),asin(sqrt(sum(ar.^2,2)))",1:size(v,1))
view(32,12), set(camlight("head"),"color",[1 0.84 0.6]), lighting gouraud


改造下樓上的答案,配色好難看。

我研究下如何配成彩虹色(⊙﹏⊙)


推薦閱讀:

Mathematica 有哪些不如 MATLAB 的地方?
自學 MATLAB,有哪些小項目值得推薦?
大家用matlab有遇到過哪些槽點?
如何使用MATLAB畫三維的蘋果?
初學 Matlab 要如何開始?

TAG:MATLAB |