Betsy Ross Problem
Matlab学习中的betsy ross 问题。用matlab函数画1777年的美国国旗。
五角星绘制部分是自己想出来的方法去画上的。具体代码参考如下。
先是绘制矩形的函数
1 function DrawRect(a,b,L,W,c) 2 %Adda a Rectangle to the current window .Assumes hold is on. 3 %The Rectangle has vertices (a,b),(a+L,b),(a,b+W),(a+L,b+W) 4 %The c is color which is in the form of 'rgb vector' or one of the built-in 5 %clolors such as 'r','g','y','b' 6 x=[a,a+L,a+L,a]; 7 y=[b,b,b+W,b+W]; 8 fill(x,y,c);
然后是绘制五角星的代码
1 function DrawStar(x1,y1,dr,c) 2 %the center of the five-stars is at (x1,y1) 3 %the radius of five-stars 4 %the color of the five-star 5 dtheta=2*pi/5; 6 hold on 7 axis equal off 8 j=0:4; 9 %外部五个点 10 x=x1+dr*cos(j*dtheta+pi/2); 11 y=y1+dr*sin(j*dtheta+pi/2); 12 %内部五个点 13 xl=x1+dr*cos(j*dtheta+2*pi/3)/2; 14 yl=y1+dr*sin(j*dtheta+2*pi/3)/2; 15 %Seperately take the ten points into vector 16 X=[x(1),xl(1),x(2),xl(2),x(3),xl(3),x(4),xl(4),x(5),xl(5)]; 17 Y=[y(1),yl(1),y(2),yl(2),y(3),yl(3),y(4),yl(4),y(5),yl(5)]; 18 %then draw it. 19 fill(X,Y,c);
然后调用上面的两个函数,绘制整个旗帜
1 function DrawFlag(a,b,L1,W1,L2,r1,r2) 2 %Adds a 13-star,13-stripe Colonial flag to the current 3 %Figure window.Assumes hold id on 4 %The flag is L1-by-W1 with lower left corner at(a,b). 5 %The length fo the blue area is L2.The ring of stars has radius r1 and its 6 %center is the center of the blue area 7 %the radius of the individual stars is r2 8 clc 9 close all 10 figure 11 hold on 12 s=W1/13; 13 axis equal off 14 for k=1:13 15 %Draw the kth stripe 16 bk=b+(k-1)*s; 17 if rem(k,2)==1&&k<=6 18 DrawRect(a,bk,L1,s,'r'); 19 elseif rem(k,2)==0&&k<=6 20 DrawRect(a,bk,L1,s,'w'); 21 elseif rem(k,2)==1&&k>=6 22 DrawRect(a+L2,bk,L1-L2,s,'r'); 23 else DrawRect(a+L2,bk,L1-L2,s,'w'); 24 end 25 end 26 DrawRect(a,b+6*s,L2,7*s,'b'); 27 %draw star 28 theta=2*pi/13; 29 xc=(a+L2)/2; 30 yc=9.5*s; 31 for k=0:12 32 xr=xc+r1*cos(k*theta+pi/2); 33 yr=yc+r1*sin(k*theta+pi/2); 34 DrawStar(xr,yr,r2,'w');5 35 end 36 hold off
转载于:https://www.cnblogs.com/sytu/p/4339799.html
Betsy Ross Problem相关推荐
- Third season twenty-third episode,Ross‘s thing on his butt???
[Scene: Chandler and Joey's, Chandler and Joey are playing with the duck and the chick.] Joey: Hey, ...
- Second season seventh episode,Ross finds out Rachel like him,what will he do???
[Scene: Monica and Rachel's apartment. Everyone is sitting at the couches, Chandler enters.] CHAN: O ...
- Tenth season third episode,Ross is going to be so tan(black)??????
[Joey and Rachel's apartment] Chandler: So, you and Rachel tonight, huh? Joey: Yeah. It's actually o ...
- Tenth season sixth episode,Ross lost grant and his girlfriend??????
Scene: Central Perk, everyone except Phoebe is there] Phoebe: (she enters) Hey- All: Hey! Rachel: Hi ...
- Seventh season nineteenth episode,what did Ross do to his cousin ?????so sick
[Scene: Central Perk, Monica and Phoebe are on the couch as Joey enters.] Phoebe: (To Joey) Oh hey! ...
- USACO Betsy's Tour 解题报告
大神做了这道题:https://www.byvoid.com/blog/usaco-544-betsys-tour.解释得非常清楚,我也是按照这种方法做的,即统计"必经点"的个数, ...
- linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.
所有的base 都要取消注释 mirrorlist 加上注释 另外所有的enable都要设为零 目录 今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现y ...
- A + B Problem
1001: A + B Problem Description 计算 A + B. Input 多组测试数据,每组测试数据占一行,包括2个整数. Output 在一行中输出结果. Sample Inp ...
- Error:(49, 1) A problem occurred evaluating project ':guideview'. Could not read script 'https://r
出现问题如下: Error:(49, 1) A problem occurred evaluating project ':guideview'. > Could not read script ...
最新文章
- ubuntu下面的chrome浏览器增加标题栏
- js正则表达exec和match的区别(转)
- PHP中的__get()和__set()方法获取设置私有属性
- js调用app方法并传承参
- android 开启子线程执行for循环_C++11之多线程 - Part2 Joining和Detaching的使用
- matlab 矩阵规定化,Matlab实现直方图规定化
- Windows Server 2016忘记密码破解方法
- js对日期进行升序排序
- win10系统电脑修改注册表设置自动锁屏时间
- 快速由PCI迁移到PCIe
- Java 方法参数传递
- Springboot毕设项目基于SpringBoot的学生宿舍水电费缴费系统的设计与实现2py81(java+VUE+Mybatis+Maven+Mysql)
- 代价高昂的免费机器人课程{人工智能与机器人教育之个人感悟}
- MySQL之TPC压缩
- 微信小程序view控件自动换行
- c++ const 转非const
- IBL-镜面反射(预滤波篇)
- 使用VS C#实现距离的计算(点点、点线、点面、线面、线线、面面)
- 基于大数据风控技术,PBOC二代人行征信报告的解读哪家好
- Android Canvas Layers
热门文章
- stl vector 容量与大小之间的关系
- bzoj 3262: 陌上花开(cdq分治)
- 最大权闭合子图(poj 2987 Firing)
- Canny提取图像边缘后使用闭运算连接断线
- [debug] RuntimeError: CUDA error: no kernel image is available for execution on the device
- python文件夹,文件监听工具(pyinotify,watchdog)
- [BUG]Git Sever搭建与相关错误处理
- Java 窗口菜单
- 使用C++实现二叉搜索树的数据结构
- NSArray 的遍历