关键词不能为空

当前您在: 主页 > 英语 >

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如何画五星红旗的相关文章

  • 爱心与尊严的高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊严高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊重的作文题库

    1.作文关爱与尊重议论文 如果说没有爱就没有教育的话,那么离开了尊重同样也谈不上教育。 因为每一位孩子都渴望得到他人的尊重,尤其是教师的尊重。可是在现实生活中,不时会有

    小学作文
  • 爱心责任100字作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任心的作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文