• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

matlab根据圆心和半径画圆三种方式

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
% 已知圆心和半径画圆:参考:https://blog.csdn.net/ZLK961543260/article/details/70216089
% 对比三种画圆方法,运算时长对比如下
% viscircle:0.22;比较快
% rectangle:0.21;比较快
% function:0.39:慢

[Type Sheet Format]=xlsfinfo(\'现状OD数据及其他数据.xls\');
OD=xlsread(\'现状OD数据及其他数据.xls\',Sheet{1});
center_area=xlsread(\'现状OD数据及其他数据.xls\',Sheet{2});

x_pos=center_area(:,4);   %数据第四列为x坐标(米)
y_pos=center_area(:,5);   %数据第五列为y坐标(米)
area=center_area(:,3);    %数据第3列为面积(平方米):注意与x,y的坐标对应
r_all=sqrt(area/pi);      %计算节点覆盖半径,为后文画圆做准备
nanbool=isnan(r_all);     %数据1到4行为四个物流园区,通过r为nan,提取出四个物流园区
first_node_num=length(find(nanbool==1)); %统计物流园区个数
r_index=find(nanbool==0,1);              %节点开始的行数index
r=r_all(r_index:end);                    %r存储节点的覆盖半径
jam_coef=center_area(r_index:end,6);     %数据第六列为交通拥堵系数,只有节点才有,具体在散点图中的标注用text实现,
% 具体标注可参考https://zhidao.baidu.com/question/924100748051179779.html
% 散点图颜色可参考:https://zhidao.baidu.com/question/521200141403285445.html?qbl=relate_question_1&word=matlabscatter%B1%EA%D7%A2
% 具体标注和颜色还未完善

% 方法一:viscircle
%用viscircle画节点的覆盖范围,用scatter画物流园区和节点
x_2_pos=x_pos(r_index:end);     %节点x
y_2_pos=y_pos(r_index:end);     %节点y
centers=[x_2_pos,y_2_pos];      %节点圆心位置
tic
fig1=figure
colors = {\'b\',\'r\',\'g\',\'y\',\'k\'};
%定义colors,后文画图方便,也可以只是掉,直接在后文加入\'k\',\'g\'等,具体可查询matlab画图颜色标记表示
viscircles(centers,r,\'color\',colors{1});    %matlab自带函数:已知圆心和半径画圆
hold on
scatter(x_2_pos,y_2_pos,\'filled\');
%已知x,y坐标,画散点图命令scatter(x,y),filled表示圆是实心填充
hold on                                     %画多个圆时用hold on命令
scatter(x_pos(1:4),y_pos(1:4),\'filled\');    %数字4指的是物流园区的个数,均可以替换成first_node_num
%scatter(x_pos(1:first_node_num),y_pos(1:first_node_num),\'filled\'); 
toc

% % 方法二:rectangle
% % 用矩形函数rectangle 画圆,rectangle函数一次只能画一个矩形/圆;需要用到循环,与viscircle比较计算时长,tic,toc
tic
fig2=figure
%矩形函数画多个圆只能用for命令进行循环,用矩阵读取会发生错误
for i=1:length(r)
rectangle(\'Position\',[x_2_pos(i)-r(i),y_2_pos(i)-r(i),2*r(i),2*r(i)],\'Curvature\',[1,1],\'linewidth\',1,\'EdgeColor\',\'b\')  %rectangle(\'position\',[x_pos,y_pos,length,width])
end  %[1,1]表示构造圆/椭圆
hold on
scatter(x_2_pos,y_2_pos,\'filled\');
hold on
scatter(x_pos(1:4),y_pos(1:4),\'filled\');
%scatter(x_pos(1:first_node_num),y_pos(1:first_node_num),\'filled\'); 
toc

% 方法三:构建function 
tic
fig3=figure
for j=1:length(r)
x=x_2_pos(j);
y=y_2_pos(j);
r1=r(j);
% function [] = plot1( x,y,r1 )
theta=0:0.1:2*pi;
Circle1=x+r1*cos(theta);
Circle2=y+r1*sin(theta);
c=[123,14,52]; %color:BGR? RBG?help
plot(Circle1,Circle2,\'c\',\'linewidth\',1);
hold on
end
scatter(x_2_pos,y_2_pos,\'filled\');
hold on
scatter(x_pos(1:4),y_pos(1:4),\'filled\');
toc

绘图结果:

figure1:

figure2:

figure3:

赛题具体地图:

 

 

参考资料:

1.https://blog.csdn.net/ZLK961543260/article/details/70216089

2.数据来源为2017年研究生数学建模竞赛F题赛题数据

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi XE7 FireDAC中间件&Exe+DLL主副架构源码发布时间:2022-07-18
下一篇:
delphi里动态创建AlphaControls实现换肤发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap