目录
0 咏玫瑰
1 美丽的粉王后
1.1 代码
1.2 展现
2 蓝玫瑰
2.1 代码
2.2 结果
0 咏玫瑰 【#|花仙子——玫瑰(Matlab实现)】
文章图片
中国的花中王后——玫瑰,很璀璨,也极其美丽,首先呢,先用一首诗歌赞赏以下,然后再用代码实现。
咏玫瑰
堪爱独玫瑰。
簪鬓放娇怜紫艳,
伴糖津咽胜红蕤。
枯润总香飞。
春风临大陆,百花争光辉。
在这百花之中,却独爱玫瑰。为什么呢?
插在头上做装饰,艳丽四射,美不胜收; 做在汤羹里当食物,又能够止咳生津,正是适合春天的花茶。最重要的一点,无论润泽或是枯萎,总有一股淡淡的清香。
文章图片
1 美丽的粉王后 花中仙子
1.1 代码
function drawrose2
grid on
[x,t]=meshgrid((0:24)./24,(0:0.5:575)./575.*20.*pi-4*pi);
p=(pi/2)*exp(-t./(8*pi));
change=sin(20*t)/150;
u=1-(1-mod(3.3*t,2*pi)./pi).^4./2+change;
y=2*(x.^2-x).^2.*sin(p);
r=u.*(x.*sin(p)+y.*cos(p)).*1.5;
h=u.*(x.*cos(p)-y.*sin(p));
map=[0.91760.74900.3765
0.91880.75130.3879
0.92000.75370.3992
0.92110.75600.4106
0.92230.75840.4220
0.92350.76080.4334
0.92470.76310.4447
0.92590.76540.4561
0.92700.76780.4675
0.92820.77020.4788
0.92940.77250.4902
0.92980.76980.5008
0.93020.76700.5114
0.93060.76430.5220
0.93100.76150.5326
0.93140.75880.5432
0.93170.75610.5537
0.93210.75330.5643
0.93250.75060.5749
0.93290.74780.5855
0.93330.74510.5961
0.92900.74040.5894
0.92470.73570.5828
0.92040.73100.5761
0.91610.72630.5694
0.91180.72150.5627
0.90740.71680.5561
0.90310.71210.5494
0.89880.70740.5427
0.89450.70270.5361
0.89020.69800.5294
0.88900.69760.5388
0.88780.69720.5482
0.88670.69680.5576
0.88550.69640.5670
0.88430.69610.5765
0.88310.69570.5859
0.88190.69530.5953
0.88080.69490.6047
0.87960.69450.6141
0.87840.69410.6235
0.88270.69880.6364
0.88700.70350.6494
0.89140.70820.6623
0.89570.71290.6753
0.90000.71770.6882
0.90430.72240.7011
0.90860.72710.7141
0.91300.73180.7270
0.91730.73650.7400
0.92160.74120.7529
0.91530.72750.7545
0.90900.71370.7560
0.90280.70000.7576
0.89650.68630.7592
0.89020.67250.7608
0.88390.65880.7623
0.87760.64510.7639
0.87140.63140.7655
0.86510.61760.7670
0.85880.60390.7686
0.85800.59060.7557
0.85720.57720.7427
0.85650.56390.7298
0.85570.55060.7168
0.85490.53730.7039
0.85410.52390.6910
0.85330.51060.6780
0.85260.49730.6651
0.85180.48390.6521
0.85100.47060.6392
0.84200.44470.6110
0.83300.41880.5827
0.82390.39300.5545
0.81490.36710.5263
0.80590.34120.4980
0.79690.31530.4698
0.78790.28940.4416
0.77880.26360.4134
0.76980.23770.3851
0.76080.21180.3569];
set(gca,'CameraPosition',[2 2 2])
hold on
surface(r.*cos(t),r.*sin(t),h,'EdgeAlpha',0.1,...
'EdgeColor',[0.5 0.5 0.5],'FaceColor','interp')
colormap(map)end
1.2 展现
文章图片
2 蓝玫瑰 2.1 代码
function roseBall
clear;
clc
%曲面数据计算
%==========================================================================
[x,t]=meshgrid((0:24)./24,(0:0.5:575)./575.*20.*pi+4*pi);
p=(pi/2)*exp(-t./(8*pi));
change=sin(15*t)/150;
u=1-(1-mod(3.6*t,2*pi)./pi).^4./2+change;
y=2*(x.^2-x).^2.*sin(p);
r=u.*(x.*sin(p)+y.*cos(p));
h=u.*(x.*cos(p)-y.*sin(p));
%颜色映射表
%==========================================================================
hMap=(h-min(min(h)))./(max(max(h))-min(min(h)));
col=size(hMap,2);
colorList=[0.02000.04000.3900
00.09000.5800
00.13000.6400
0.02000.06000.6900
00.08000.7900
0.01000.18000.8500
00.13000.9600
0.01000.26000.9900
00.35000.9900
0.07000.62001.0000
0.17000.69001.0000];
% colorList=[0.21000.09000.3800
%0.29000.07000.4700
%0.40000.11000.4900
%0.55000.16000.5100
%0.75000.24000.4700
%0.89000.32000.4100
%0.97000.49000.3700
%1.00000.56000.4100
%1.00000.69000.4900
%1.00000.82000.5900
%0.99000.92000.6700
%0.98000.95000.7100];
colorFunc=colorFuncFactory(colorList);
dataMap=colorFunc(hMap');
colorMap(:,:,1)=dataMap(:,1:col);
colorMap(:,:,2)=dataMap(:,col+1:2*col);
colorMap(:,:,3)=dataMap(:,2*col+1:3*col);
function colorFunc=colorFuncFactory(colorList)
xx=(0:size(colorList,1)-1)./(size(colorList,1)-1);
y1=colorList(:,1);
y2=colorList(:,2);
y3=colorList(:,3);
colorFunc=@(X)[interp1(xx,y1,X,'linear')',interp1(xx,y2,X,'linear')',interp1(xx,y3,X,'linear')'];
end%曲面旋转及绘制
%==========================================================================
surface(r.*cos(t),r.*sin(t),h+0.35,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)hold onsurface(r.*cos(t),r.*sin(t),-h-0.35,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)
Xset=r.*cos(t);
Yset=r.*sin(t);
Zset=h+0.35;
yaw_z=pi*72/180;
roll_x=pi-acos(-1/sqrt(5));
R_z_2=[cos(yaw_z),-sin(yaw_z),0;
sin(yaw_z),cos(yaw_z),0;
0,0,1];
R_z_1=[cos(yaw_z/2),-sin(yaw_z/2),0;
sin(yaw_z/2),cos(yaw_z/2),0;
0,0,1];
R_x_2=[1,0,0;
0,cos(roll_x),-sin(roll_x);
0,sin(roll_x),cos(roll_x)];
[nX,nY,nZ]=rotateXYZ(Xset,Yset,Zset,R_x_2);
surface(nX,nY,nZ,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)for k=1:4
[nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_2);
surface(nX,nY,nZ,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)
end[nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_1);
for k=1:5
[nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_2);
surface(nX,nY,-nZ,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)
end
%--------------------------------------------------------------------------
function [nX,nY,nZ]=rotateXYZ(X,Y,Z,R)
nX=zeros(size(X));
nY=zeros(size(Y));
nZ=zeros(size(Z));
for i=1:size(X,1)
for j=1:size(X,2)
v=[X(i,j);
Y(i,j);
Z(i,j)];
nv=R*v;
nX(i,j)=nv(1);
nY(i,j)=nv(2);
nZ(i,j)=nv(3);
end
end
end
%axes属性调整
%==========================================================================
ax=gca;
grid on
ax.GridLineStyle='--';
ax.LineWidth=1.2;
ax.XColor=[1,1,1].*0.4;
ax.YColor=[1,1,1].*0.4;
ax.ZColor=[1,1,1].*0.4;
ax.DataAspectRatio=[1,1,1];
ax.DataAspectRatioMode='manual';
ax.CameraPosition=[-6.5914-24.1625-0.0384];
end
2.2 结果
文章图片
推荐阅读
- #|信息时代——微信防撤回(Python实现)
- python|基于股票大数据分析的Python入门实战(实践记录)(持续更新)
- 量子计算|CDR(线性模型处理量子噪声处理方法)
- python|Pytorch中判断两个tensor是否相等
- 笔记|Day30.守护线程、定时器、消费者模式 | wait、notify方法
- #|DVWA-sql注入漏洞详解
- Python数据可视化|Python数据可视化之随机漫步
- ★MATLAB算法仿真经验|在隧道内放置多个地感线圈,车辆通过时、对通过的相邻两个线圈的脉冲信号数据进行实时采集,首先利用云模型算法,计算得到车速
- 博图PLC程序 停车场控制系统