MATLAB 50行代码绘制超好看的旋转九边形
Posted slandarer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MATLAB 50行代码绘制超好看的旋转九边形相关的知识,希望对你有一定的参考价值。
运行效果
完整代码
function nonagon20
% @author:slandarer
% axes属性设置
ax=gca;
hold on;axis equal;
ax.Position=[0 0 1 1];
ax.XLim=[-6,6];ax.YLim=[-6,6];
ax.XColor='none';ax.YColor='none';
ax.Color=[0,44,106]./255;
% 初始集合构建
t=linspace(0,2*pi,9);
NGon=[cos(t'),sin(t')].*2;
NGonSet=repmat(NGon',[20,1]);
rotate18=arrayfun(@(k)[cos(pi/10),-sin(pi/10);sin(pi/10),cos(pi/10)]^k,0:19,'UniformOutput',false);
rotate18=blkdiag(rotate18:);
NGonSet=rotate18*NGonSet;
% 渐变颜色矩阵创建
C1=[237,210,155]./255;
C2=[219,90,117]./255;
ct=linspace(0,1,11);
CList=[interp1([0,1],[C1(1),C2(1)],ct,'linear')',...
interp1([0,1],[C1(2),C2(2)],ct,'linear')',...
interp1([0,1],[C1(3),C2(3)],ct,'linear')'];
CList=[CList;flipud(CList(2:10,:))];CList=[CList(5:end,:);CList(1:4,:)];
% 初始图像绘制
NGonHdl20=[];
for i=1:20
NGonHdli=fill(NGonSet(i*2-1,:)+cos((i-1)*pi/10)*2,...
NGonSet(i*2,:)+sin((i-1)*pi/10)*2,CList(i,:),...
'FaceAlpha',.12,'LineWidth',1.3,'EdgeColor',CList(i,:));
end
% 旋转矩阵
rotateMat=arrayfun(@(k)[cos(k),-sin(k);sin(k),cos(k)],ones([1,20]).*(2*pi/120),'UniformOutput',false);
rotateMat=blkdiag(rotateMat:);
% 旋转
for n=1:1000
NGonSet=rotateMat*NGonSet;
for i=1:20
NGonHdli.XData=NGonSet(i*2-1,:)+cos((i-1)*pi/10)*2;
NGonHdli.YData=NGonSet(i*2,:)+sin((i-1)*pi/10)*2;
end
pause(.05)
drawnow
end
end
以上是关于MATLAB 50行代码绘制超好看的旋转九边形的主要内容,如果未能解决你的问题,请参考以下文章
matlab三维网格绘图函数meshmeshcmeshzmeshgridsurfmatlab图行绘制五