关键词不能为空

当前您在: 主页 > 英语 >

matlab如何画五星红旗

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-01 21:49
tags:

-

2021年2月1日发(作者:fav)


生成五角星顶点的子函数(


GetPentagramVertices .m





function [x y] = GetPentagramVertices(centerPos, radius, orientation)



%


子函数:



获得五角星的十个顶点



%orientation


定位



Rad_ext = radius .* ones(1,5);


%ones


生成


1


行五列的矩 阵,所有参数为


1


Ori_ext = ([0:72:359] + 90 +orientation).* pi/ 180;


%[0:72:359]



72


度为间隔产生五个数



Rad_int = radius .* sind(18)./sind(126) .* ones(1,5);


% sind(30)=0.5


Ori_int = ([0:72:359] - 90 +orientation).* pi/ 180;



Ori_int = Ori_int([4 5 1 2 3]);


%


强制换序



Rad_all = zeros(1,10);


Ori_all = zeros(1,10);



Rad_all([1:2:10 2:2:10]) = [Rad_ext Rad_int];


Ori_all([1:2:10 2:2:10]) = [Ori_ext Ori_int];



[x y] = pol2cart(Ori_all, Rad_all);


%pol2cart< /p>



MATLAB


中,


该函数用于把极坐标(柱坐标)转换为笛卡尔坐标(指平面直角

< br>坐标或空间直角坐标)


;把柱坐标


(THETA,RHO ,Z)


转换为对应的三维笛卡尔坐标


(X,Y,Z)

< p>



x = x + centerPos(1);


y = y + centerPos(2);




主程序


1


paintFSRF_script.m


程序是画静态的五星红旗,并将图像以


''


保存在当前目录 下。这个五


星红旗的比例是按照《中华人民共和国国旗制法说明》绘制的





第一行是调整国旗分辨率的,可以自行修改,但是要保持


3:2

的比例




flag_dimension_in_pixel = [600 400];



figure_leftbottom_pos = [100 100];



bkg_color = [1 0 0];



star_color = [1 1 0];



flag_horiz_units_num = 30;



flag_verti_units_num = 20;



star_vertices_x = zeros(10, 5);



star_vertices_y = zeros(10, 5);



stars(5).center_pos = [];



stars(1).center_pos = [5 15];



stars(1).radius = 3;



stars(1).orientation = 0;



stars(2).center_pos = [10 18];



stars(2).radius = 1;



stars(2).orientation = 0;



stars(3).center_pos = [12 16];



stars(3).radius = 1;



stars(3).orientation = 0;



stars(4).center_pos = [12 13];



stars(4).radius = 1;



stars(4).orientation = 0;



stars(5).center_pos = [10 11];



stars(5).radius = 1;



stars(5).orientation = 0;


%


类似于


c#


的自定义函数调用?



for i = 2:5


dists = deal(stars(i).center_pos - stars(1).center_pos);


stars(i).orientation = atan(dists(2)/dists(1)).*180/pi + 90;


end



%% Prepare the background



flag_figure = figure('Units', 'pixels', ...


'Position', [figure_leftbottom_pos, flag_dimension_in_pixel]);



flag_axes = axes('Parent', flag_figure, 'Units','pixels', ...


'Position', [1 1 flag_dimension_in_pixel], 'Color', [1 0 0]);



set(flag_axes,


'XLim',


[0


flag_horiz_units_num],


'YLim',


flag_verti_units_num]);



rectangle('Position', [0 0 flag_horiz_units_num flag_verti_units_num], ...


'FaceColor', bkg_color ,'EdgeColor' ,bkg_color);



set(flag_axes, 'Visible','off');



%% Get the Star's Vertices



for i = 1:5


[star_vertices_x(:,i) star_vertices_y(:, i)] = ...


GetPentag ramVertices(stars(i).center_pos, ...


stars(i).radius,stars(i).orientation);



end



star_handles = patch(star_vertices_x, star_vertices_y, star_color);



set(star_handles, 'EdgeColor', star_color);


flag_image = frame2im(getframe(flag_figure));



imwrite(flag_image, '');



%


如装有


Image Processing Toolbox


的话,解注下面几行可以保存图形文件




%


% [filename, pathname, filterindex] = ...


% uiputfile('*','Save the Nation Flag as...')


%


% imwrite(flag_image, [pathname filename]);




[0


主程序


2


paintFlyingFSRF_script.m



程序是飘扬的五星红旗,效果是


3D


实时渲染 出来的,所以速度有点慢,机器够牛的同学可


以试着将第一行的分辨率改大



flag_size = [600 400]; % Change as you see fit



flag_dimension_in_pixel = flag_size; %[600 400];



figure_leftbottom_pos = [100 100];



bkg_color = [1 0 0];



star_color = [1 1 0];



flag_horiz_units_num = 30;



flag_verti_units_num = 20;



star_vertices_x = zeros(10, 5);



star_vertices_y = zeros(10, 5);



stars(5).center_pos = [];



stars(1).center_pos = [5 15];



stars(1).radius = 3;



stars(1).orientation = 0;



stars(2).center_pos = [10 18];



stars(2).radius = 1;



stars(2).orientation = 0;



stars(3).center_pos = [12 16];



stars(3).radius = 1;



stars(3).orientation = 0;



stars(4).center_pos = [12 13];



stars(4).radius = 1;



stars(4).orientation = 0;



stars(5).center_pos = [10 11];



stars(5).radius = 1;



stars(5).orientation = 0;



for i = 2:5


dists = deal(stars(i).center_pos - stars(1).center_pos);


stars(i).orientation = atan(dists(2)/dists(1)).*180/pi + 90;


end



%% Prepare the background



flag_figure = figure('Units', 'pixels', ...


'Position', [figure_leftbottom_pos, flag_dimension_in_pixel]);



flag_axes = axes('Parent', flag_figure, 'Units','pixels', ...


'Position', [1 1 flag_dimension_in_pixel], 'Color', [1 0 0]);



set(flag_axes,


'XLim',


[0


flag_horiz_units_num],


'YLim',


flag_verti_units_num]);



rectangle('Position', [0 0 flag_horiz_units_num flag_verti_units_num], ...


'FaceColor', bkg_color ,'EdgeColor' ,bkg_color);



set(flag_axes, 'Visible','off');



%% Get the Star's Vertices



for i = 1:5


[star_vertices_x(:,i) star_vertices_y(:, i)] = ...


GetPentag ramVertices(stars(i).center_pos, ...


stars(i).radius,stars(i).orientation);



end



star_handles = patch(star_vertices_x, star_vertices_y, star_color);



set(star_handles, 'EdgeColor', star_color);


[0

-


-


-


-


-


-


-


-



本文更新与2021-02-01 21:49,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/595334.html

matlab如何画五星红旗的相关文章

  • 余华爱情经典语录,余华爱情句子

    余华的经典语录——余华《第七天》40、我不怕死,一点都不怕,只怕再也不能看见你——余华《第七天》4可是我再也没遇到一个像福贵这样令我难忘的人了,对自己的经历如此清楚,

    语文
  • 心情低落的图片压抑,心情低落的图片发朋友圈

    心情压抑的图片(心太累没人理解的说说带图片)1、有时候很想找个人倾诉一下,却又不知从何说起,最终是什么也不说,只想快点睡过去,告诉自己,明天就好了。有时候,突然会觉得

    语文
  • 经典古训100句图片大全,古训名言警句

    古代经典励志名言100句译:好的药物味苦但对治病有利;忠言劝诫的话听起来不顺耳却对人的行为有利。3良言一句三冬暖,恶语伤人六月寒。喷泉的高度不会超过它的源头;一个人的事

    语文
  • 关于青春奋斗的名人名言鲁迅,关于青年奋斗的名言鲁迅

    鲁迅名言名句大全励志1、世上本没有路,走的人多了自然便成了路。下面是我整理的鲁迅先生的名言名句大全,希望对你有所帮助!当生存时,还是将遭践踏,将遭删刈,直至于死亡而

    语文
  • 三国群英单机版手游礼包码,三国群英手机单机版攻略

    三国群英传7五神兽洞有什么用那是多一个武将技能。青龙飞升召唤出东方的守护兽,神兽之一的青龙。玄武怒流召唤出北方的守护兽,神兽之一的玄武。白虎傲啸召唤出西方的守护兽,

    语文
  • 不收费的情感挽回专家电话,情感挽回免费咨询

    免费的情感挽回机构(揭秘情感挽回机构骗局)1、牛牛(化名)向上海市公安局金山分局报案,称自己为了挽回与女友的感情,被一家名为“实花教育咨询”的情感咨询机构诈骗4万余元。

    语文