-
生成五角星顶点的子函数(
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)
。
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
-
-
-
-
-
-
-
-
-
上一篇:数据结构C语言版 求关节点
下一篇:拓扑排序课程设计报告