用Matlab画一朵漂亮玫瑰🌹

Matlab的facebook官方账号给出了一段代码,运行代码可以画出一朵漂亮的红玫瑰。

Credit: Matlab

n = 800;
A = 1.995653;
B = 1.27689;
C = 8;
r=linspace(0,1,n);
theta=linspace(-2,20pi,n);
[R,THETA]=ndgrid(r,theta);
% define the number of petals we want per cycle. Roses have 3 and a bit.
petalNum=3.6;
x = 1 – (1/2)((5/4)(1 – mod(petalNumTHETA, 2pi)/pi).^2 – 1/4).^2;
phi = (pi/2)exp(-THETA/(Cpi));
y = A(R.^2).(BR – 1).^2.sin(phi);
R2 = x.(R.sin(phi) + y.cos(phi));
X=R2.sin(THETA);
Y=R2.cos(THETA);
Z=x.(R.cos(phi)-y.*sin(phi));
% % define a red map for our rose colouring
red_map=linspace(1,0.25,10)’;
red_map(:,2)=0;
red_map(:,3)=0;
clf
surf(X,Y,Z,’LineStyle’,’none’)
view([-40.50 42.00])
colormap(red_map)

—Matlab codes to plot a beautiful red rose. Credit: Matlab

亲测有效~

改了几行代码,换了个颜色,换成了一朵蓝玫瑰。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注