MATLAB制作漂亮时钟.doc_第1页
MATLAB制作漂亮时钟.doc_第2页
MATLAB制作漂亮时钟.doc_第3页
MATLAB制作漂亮时钟.doc_第4页
MATLAB制作漂亮时钟.doc_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

精品文档 1欢迎下载 MATLABMATLAB 制作漂亮手表制作漂亮手表 1 1 一 问题一 问题的的提出提出 1 1 二 理论分析二 理论分析 1 1 三 实验步骤三 实验步骤 1 1 四 程序实现四 程序实现 2 2 五 实验结果及结果分析五 实验结果及结果分析 5 5 六 程序及其说明六 程序及其说明 8 8 MATLABMATLAB 制作漂亮手表制作漂亮手表 一 问题的提出一 问题的提出 随着科技的日新月异 人们的生活节奏变得越来越快 而准 确的把我时间也变得越来越重要 几乎人人都会携带可以知道 时间的东西 比如手表 手机 怀表 于是在此提出问题 如 何通过 matlab 数字化模拟日常生活中所用的手表的转动 二 理论分析二 理论分析 完整的时钟界面有时针 分针 秒针以及刻度等组成 而要 用 matlab 模拟出这些部件 则只需由外至内 一部部的模拟出 表面的图形 以及它的运转法则 精品文档 2欢迎下载 三 实验步骤三 实验步骤 1 了解手表的表盘中由哪些东西构成 将需要通过 matlab 作 出来的部件记下 2 观察手表的秒针 分针 以及时针的运转规律 构想出通 过 matlab 来实现指针的转动方法 3 着手编写 matlab 程序来实现这一过程 4 完成程序 检验程序的可行性 并完善 使作出来的手表 表盘尽可能的美化 5 完成实验报告 四 程序实现四 程序实现 1 画一个大的圆圈 表示手表的最外层的圈圈 通过 plot 画 圆来实现 x y 用参数方程确定 2 通过 line 画直线的方式 画出表盘中得分针和秒针的小的 刻度 一共 60 个 精品文档 3欢迎下载 3 同样的方式 画出时针的大的刻度 一共 12 个 并在正上 方的刻度下表上 12 4 运用 clock 指令读取系统时间 并将其作为初始时间 5 采用同样的方式分别做出第一 第二 第三个小圆盘 具 体程序就不在此给出了 6 分别做出大表盘以及小表盘中得指针 采用 fill 指令分别 实现时针 分针和秒针 在此列举大表盘中得时针做出方法 7 加入以数字形式显示时间的指令 具体实现方法如下 精品文档 4欢迎下载 显示初始时间 8 设计指针的运转 当秒针每转动一秒时 相应的改变大表 盘中秒针 分针 以及时针的位置 以及小圆圈中得指针位置 数据的改变 大圆圈的指针数据 小圆圈中指针的数据 精品文档 5欢迎下载 图像中指针的位置改变 9 当指针转动一圈时 相应的数据应如何变化 10 数字显示也许相应的改变 精品文档 6欢迎下载 11 为使秒针的运动符合时间的规律 采用 pause 指令 五 实验结果及结果分析五 实验结果及结果分析 运行程序 得到结果 精品文档 7欢迎下载 精品文档 8欢迎下载 精品文档 9欢迎下载 六 程序及其说明六 程序及其说明 clear clf 作出大的表盘 set gcf name 钟表 color white theta linspace 0 2 pi 10000 r 10 x r cos theta y r sin theta shg plot x y axis 12 12 15 12 精品文档 10欢迎下载 axis equal hold on axis off text 0 6 9 fontsize 20 12 theta0 xa xb ya yb for i 1 60 画出60个刻度 theta0 i i pi 30 xa r 0 3 cos theta0 i xb r 0 3 sin theta0 i ya r cos theta0 i yb r sin theta0 i line xa ya xb yb end for i 1 12 画出12个时针的刻度 为了美观 采取个别不画的原则 if i 1 i 3 i 5 i 9 continue end theta0 i i pi 6 xa r 1 5 cos theta0 i xb r 1 5 sin theta0 i ya r 0 36 cos theta0 i 精品文档 11欢迎下载 yb r 0 36 sin theta0 i line xa ya xb yb linewidth 3 end for i 1 12 在60个小刻度的基础上对时针的刻 度加粗 theta0 i i pi 6 xa r 0 3 cos theta0 i xb r 0 3 sin theta0 i ya r cos theta0 i yb r sin theta0 i line xa ya xb yb linewidth 3 end t clock h0 t 4 设定初始时间 m0 t 5 s0 floor t 6 thetas1 15 s0 pi 30 计算3个小表盘中指针的初始角 度 thetam1 15 m0 pi 30 s0 pi 1800 thetah1 6 h0 pi 12 m0 pi 720 s0 pi 43200 作第一个小表盘 r1 0 6 theta1 0 pi 6 精品文档 12欢迎下载 r1 3 theta1 linspace 0 2 pi 10000 x1 0 r1 0 cos theta1 0 y1 0 r1 0 sin theta1 0 x1 x1 0 r1 cos theta1 y1 y1 0 r1 sin theta1 plot x1 y1 theta 10 x1a x1b y1a y1b for i 1 12 画出第一个小表盘的刻度 theta 10 i i pi 6 x1a x1 0 r1 0 3 cos theta 10 i x1b y1 0 r1 0 3 sin theta 10 i y1a x1 0 r1 cos theta 10 i y1b y1 0 r1 sin theta 10 i line x1a y1a x1b y1b linewidth 2 end text x1 0 r1 0 7 y1 0 6 部分刻度给予数字显示 text x1 0 r1 0 1 y1 0 18 text x1 0 0 4 y1 0 r1 0 5 12 text x1 0 0 4 y1 0 r1 0 5 24 h1x1 x1 0 0 4 cos thetah1 pi h1y1 y1 0 0 4 sin thetah1 pi 作出第一个小表盘的指针 h1x2 x1 0 0 2 cos thetah1 pi 2 h1y2 y1 0 0 2 sin thetah1 p 精品文档 13欢迎下载 i 2 h1x3 x1 0 1 8 cos thetah1 h1y3 y1 0 1 8 sin thetah1 h1x4 x1 0 0 2 cos thetah1 pi 2 h1y4 y1 0 0 2 sin thetah1 pi 2 h1 fill h1x1 h1x2 h1x3 h1x4 h1x1 h1y1 h1y2 h1y3 h1y4 h1y 1 g plot x1 0 y1 0 w markersize 6 作第二个小表盘 r2 0 6 theta2 0 5 pi 6 r2 3 theta2 linspace 0 2 pi 10000 x2 0 r2 0 cos theta2 0 y2 0 r2 0 sin theta2 0 x2 x2 0 r2 cos theta2 y2 y2 0 r2 sin theta2 plot x2 y2 theta 20 x2a x2b y2a y2b for i 1 60 画出第二个小表盘的刻度 theta 20 i i pi 30 x2a x2 0 r2 0 5 cos theta 20 i x2b y2 0 r2 0 5 sin theta 20 i y2a x2 0 r2 cos theta 20 i y2b y2 0 r2 sin theta 20 i 精品文档 14欢迎下载 line x2a y2a x2b y2b linewidth 1 end text x2 0 0 3 y2 0 r2 0 8 60 部分刻度给予数字显示 text x2 0 1 4 y2 0 1 2 20 text x2 0 2 y2 0 1 2 40 s1x1 x2 0 0 4 cos thetas1 pi s1y1 y2 0 0 4 sin thetas1 pi 作出第二个小表盘的指针 s1x2 x2 0 0 2 cos thetas1 pi 2 s1y2 y1 0 0 2 sin thetas1 p i 2 s1x3 x2 0 1 8 cos thetas1 s1y3 y2 0 1 8 sin thetas1 s1x4 x2 0 0 2 cos thetas1 pi 2 s1y4 y2 0 0 2 sin thetas1 pi 2 s1 fill s1x1 s1x2 s1x3 s1x4 s1x1 s1y1 s1y2 s1y3 s1y4 s1y 1 g plot x2 0 y2 0 w markersize 7 添加中间小圆圈 美化表盘 for i 1 60 画出12个时针的刻度 为了美观 采取个别不画的原则 if i 1 end thetas1 thetas1 pi 30 时间走动时 变化相应的表 盘的摆针的角度 thetam1 thetam1 pi 1800 thetah1 thetah1 pi 43200 sx1 r 8 cos thetas i pi 30 pi sy1 r 8 sin thetas i pi 30 pi sx2 r 0 3 cos thetas i pi 30 sy2 r 0 3 sin thetas i pi 30 mx1 r 6 cos thetam j pi 1800 pi 30 my1 r 6 sin thetam j pi 1800 pi 30 mx2 r 1 5 cos thetam j pi 1800 my2 r 1 5 sin thetam j pi 1800 mx3 r 6 cos thetam j pi 1800 pi 30 my3 r 6 sin thetam j pi 1800 pi 30 hx1 r 7 cos thetah k pi 21600 pi 25 hy1 r 7 sin thetah k pi 21600 pi 25 精品文档 20欢迎下载 hx2 r 4 cos thetah k pi 21600 hy2 r 4 sin thetah k pi 21600 hx3 r 7 cos thetah k pi 21600 pi 25 hy3 r 7 sin thetah k pi 21600 pi 25 s1x1 x2 0 0 4 cos thetas1 pi s1y1 y2 0 0 4 sin thetas1 pi s1x2 x2 0 0 2 cos thetas1 pi 2 s1y2 y1 0 0 2 sin thetas1 p i 2 s1x3 x2 0 1 8 cos thetas1 s1y3 y2 0 1 8 sin thetas1 s1x4 x2 0 0 2 cos thetas1 pi 2 s1y4 y2 0 0 2 sin thetas1 pi 2 m1x1 x3 0 0 4 cos thetam1 pi m1y1 y3 0 0 4 sin thetam1 pi m1x2 x3 0 0 2 cos thetam1 pi 2 m1y2 y3 0 0 2 sin thetam1 p i 2 m1x3 x3 0 1 8 cos thetam1 m1y3 y3 0 1 8 sin thetam1 m1x4 x3 0 0 2 cos thetam1 pi 2 m1y4 y3 0 0 2 sin thetam1 pi 2 h1x1 x1 0 0 4 cos thetah1 pi h1y1 y1 0 0 4 sin thetah1 pi 精品文档 21欢迎下载 h1x2 x1 0 0 2 cos thetah1 pi 2 h1y2 y1 0 0 2 sin thetah1 p i 2 h1x3 x1 0 1 8 cos thetah1 h1y3 y1 0 1 8 sin thetah1 h1x4 x1 0 0 2 cos thetah1 pi 2 h1y4 y1 0 0 2 sin thetah1 pi 2 set s xdata sx1 sx2 ydata sy1 sy2 画出 变化后的指针位置 set m xdata 0 mx1 mx2 mx3 0 ydata 0 my1 my2 my3 0 set h xdata 0 hx1 hx2 hx3 0 ydata 0 hy1 hy2 hy3 0 set m1 xdata m1x1 m1x2 m1x3 m1x4 m1x1 ydata m1y1 m1y 2 m1y3 m1y4 m1y1 set s1 xdata s1x1 s1x2 s1x3 s1x4 s1x1 ydata s1y1 s1y 2 s1y3 s1y4 s1y1 set h1 xdata h1x1 h1x2 h1x3 h1x4 h1x1 ydata h1y1 h1y 2 h1y3 h1y4 h1y1 i i 1 k k 1 j j 1 精品文档 22欢迎下载 s0 s0 1 计算当前时间 if s0 60 s0 0 m0 m0 1 end if m0 60 m0 0 h0 h0 1 end if h0 24 h0 0 end delete time 删除句柄 if s0 10 else if s0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论