Matlab實(shí)現(xiàn)繪制玫瑰線的示例代碼
更新時(shí)間:2022年08月26日 11:25:22 作者:slandarer
這篇文章主要為大家介紹了如何利用Matlab繪制3好看的玫瑰線,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Matlab有一定幫助,感興趣的小伙伴可以動(dòng)手試一試
繪制效果
實(shí)際上就是在進(jìn)行曲線:
的可視化,代碼非常簡單哈:
基礎(chǔ)代碼
function?roseCurve1 set(gcf,'position',get(0,'ScreenSize')); %?坐標(biāo)區(qū)域修飾 ax=gca; hold?on ax.XLim=[-.5,7.5]; ax.YLim=[-.5,10.5]; ax.Color=[0?0?0]; ax.DataAspectRatio=[1,1,1]; ax.XTick=[]; ax.YTick=[]; %?屬性列表 textProp1={'FontSize',14,'FontName','Cambria','Color',[1,1,1].*.8,'HorizontalAlignment','center'}; textProp2={'FontSize',15,'FontName','Cambria','Color',[255,227,147]./255,'HorizontalAlignment','center'}; circProp={'o','Color',[1,1,1].*.8,'MarkerSize',18,'LineWidth',1.5}; %?繪制數(shù)字 plot(1:1:7,10.*ones(1,7),circProp{:}) plot(zeros(1,10),0:9,circProp{:}) for?i=1:7,text(i,10,num2str(i),textProp1{:});end for?i=1:10,text(0,10-i,num2str(i),textProp1{:});end text(0+.2,10+.2,'q',textProp2{:}) text(0-.2,10-.2,'p',textProp2{:}) text(0,10,'\\',textProp2{:},'FontSize',18) [XMesh,YMesh]=meshgrid(1:7,1:10); qpMesh=XMesh./YMesh; %?循環(huán)繪圖 for?i=1:10 ????for?j=1:7 ????????lineMat(i,j)=plot(XMesh(i,j),10-YMesh(i,j),'Color',[1,1,1,.4],'LineWidth',1.2); ????end end thetaList=linspace(0,20*pi,1000); for?t=1:length(thetaList) ????for?i=1:10 ????????for?j=1:7 ????????????r=cos(qpMesh(i,j)*thetaList(1:t)); ????????????x=XMesh(i,j)+cos(thetaList(1:t)).*r.*.4; ????????????y=10-YMesh(i,j)+sin(thetaList(1:t)).*r.*.4; ????????????lineMat(i,j).XData=x; ????????????lineMat(i,j).YData=y; ????????end ????end ????pause(.01) end end
土味代碼
來個(gè)彩虹配色的土味代碼
function?roseCurve2 set(gcf,'position',get(0,'ScreenSize')); %?坐標(biāo)區(qū)域修飾 ax=gca; hold?on ax.XLim=[-.5,7.5]; ax.YLim=[-.5,10.5]; ax.Color=[0?0?0]; ax.DataAspectRatio=[1,1,1]; ax.XTick=[]; ax.YTick=[]; %?屬性列表 textProp1={'FontSize',14,'FontName','Cambria','Color',[1,1,1].*.8,'HorizontalAlignment','center'}; textProp2={'FontSize',15,'FontName','Cambria','Color',[255,227,147]./255,'HorizontalAlignment','center'}; circProp={'o','Color',[1,1,1].*.8,'MarkerSize',18,'LineWidth',1.5}; %?繪制數(shù)字 plot(1:1:7,10.*ones(1,7),circProp{:}) plot(zeros(1,10),0:9,circProp{:}) for?i=1:7,text(i,10,num2str(i),textProp1{:});end for?i=1:10,text(0,10-i,num2str(i),textProp1{:});end text(0+.2,10+.2,'q',textProp2{:}) text(0-.2,10-.2,'p',textProp2{:}) text(0,10,'\\',textProp2{:},'FontSize',18) [XMesh,YMesh]=meshgrid(1:7,1:10); qpMesh=XMesh./YMesh; disMesh=XMesh-YMesh+10; maxDis=max(disMesh,[],[1,2]); disMesh=mod(disMesh+6,maxDis)+1; %?構(gòu)造hsv配色 colList=hsv2rgb([linspace(0,1,maxDis)',ones(maxDis,1),ones(maxDis,1).*.7]); %?colList=pink(maxDis); %?循環(huán)繪圖 for?i=1:10 ????for?j=1:7 ????????lineMat(i,j)=plot(XMesh(i,j),10-YMesh(i,j),'Color',[colList(disMesh(i,j),:),.5],'LineWidth',1.2); ????end end thetaList=linspace(0,20*pi,1000); for?t=1:length(thetaList) ????for?i=1:10 ????????for?j=1:7 ????????????r=cos(qpMesh(i,j)*thetaList(1:t)); ????????????x=XMesh(i,j)+cos(thetaList(1:t)).*r.*.4; ????????????y=10-YMesh(i,j)+sin(thetaList(1:t)).*r.*.4; ????????????lineMat(i,j).XData=x; ????????????lineMat(i,j).YData=y; ????????end ????end ????pause(.01) end end
哈哈哈果然彩虹色畫出來還是太土了:
若是將代碼
colList=hsv2rgb([linspace(0,1,maxDis)',ones(maxDis,1),ones(maxDis,1).*.7]);
修改為:
colList=pink(maxDis);
以上就是Matlab實(shí)現(xiàn)繪制玫瑰線的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于Matlab玫瑰線的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Qt?timerEvent實(shí)現(xiàn)簡單秒表功能
這篇文章主要為大家詳細(xì)介紹了Qt?timerEvent實(shí)現(xiàn)簡單秒表功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08C++ 使用PrintWindow實(shí)現(xiàn)窗口截圖功能
這篇文章主要介紹了C++ 如何使用PrintWindow實(shí)現(xiàn)窗口截圖功能,文中示例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-08-08