利用Matlab繪制好看的旋轉(zhuǎn)九邊形
更新時間:2022年03月24日 09:31:48 作者:slandarer
這篇文章主要為大家介紹了如何利用Matlab繪制超好看的旋轉(zhuǎn)九邊形。文中的示例代碼講解詳細,對我們學習Matlab有一定幫助,需要的可以參考一下
PART.0 使用效果
PART.1 程序說明
這個代碼主要復(fù)刻的Clayton Shonkwiler使用Wolfram繪制的作品(二十個旋轉(zhuǎn)的正九變形),據(jù)說其靈感來源于Thomas Davis的一些作品,Clayton Shonkwiler的更多作品可以在這個地址查看
PART.2 完整代碼
function nonagon20 % @author:slandarer % axes屬性設(shè)置 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; % 初始集合構(gòu)建 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; % 漸變顏色矩陣創(chuàng)建 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,:)]; % 初始圖像繪制 NGonHdl{20}=[]; for i=1:20 NGonHdl{i}=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 % 旋轉(zhuǎn)矩陣 rotateMat=arrayfun(@(k)[cos(k),-sin(k);sin(k),cos(k)],ones([1,20]).*(2*pi/120),'UniformOutput',false); rotateMat=blkdiag(rotateMat{:}); % 旋轉(zhuǎn) for n=1:1000 NGonSet=rotateMat*NGonSet; for i=1:20 NGonHdl{i}.XData=NGonSet(i*2-1,:)+cos((i-1)*pi/10)*2; NGonHdl{i}.YData=NGonSet(i*2,:)+sin((i-1)*pi/10)*2; end pause(.05) drawnow end end
到此這篇關(guān)于利用Matlab繪制好看的旋轉(zhuǎn)九邊形的文章就介紹到這了,更多相關(guān)Matlab旋轉(zhuǎn)九邊形內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++實現(xiàn)百度坐標(BD09)及GCJ02與WGS84之間的轉(zhuǎn)換
這篇文章主要為大家詳細介紹了C++實現(xiàn)百度坐標(BD09)及GCJ02與WGS84之間的轉(zhuǎn)換的方法,文中的示例代碼講解詳細,希望對大家有所幫助2023-03-03