插补程序源代码_第1页
插补程序源代码_第2页
插补程序源代码_第3页
插补程序源代码_第4页
插补程序源代码_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

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

文档简介

1、插补程序源代码目录1逐点比较法插补c语言程序源代码022逐点比较法圆弧插补 VB源程序 073逐点比较法直线插补VB源程序114时间分割法直线插补参考 VB程序 135时间分割法圆弧插补 VB源程序 141 / 141 逐点比较法插补 c 语言程序源代码#include "conio.h"#include "graphics.h"#include "process.h"#define Ni_circle 0#define Shun_circle 1void init_graph();void draw_Base_circle();vo

2、id draw_cabu_circle();void close_graph();void acrroods();static float x0,y0;void line_cabu(), draw_line(),draw_line_cabu();void line_cabu() /* 此函数控制直线插步两次 */int i;init_graph();sleep(1);for(i=0;i<2;i+)line(0,120,300,120); outtextxy(310,120,"Z");line(100,10,100,300); outtextxy(110,300,&qu

3、ot;X");outtextxy(90,130,"O");draw_line();if(i=0)draw_line_cabu(6);else draw_line_cabu(2);gotoxy(50,5);getch();cleardevice();setcolor(WHITE);void draw_line()/* 画直线 */line(100,120,600,450);textcolor(YELLOW);directvideo=0;gotoxy(45,5); cprintf("Line from:X0Y0 Z0 ");gotoxy(45,6)

4、; cprintf("Line to :X500 Y0 Z330");gotoxy(45,7); cprintf("Units :Pixel");gotoxy(45,8); cprintf("Line now:");void draw_line_cabu(int step)/* 关键的直线插补函数 */2 / 14int Xe=600,Ye=450;float Fm,Xm=100,Ym=120;setcolor(RED);moveto(Xm,Ym);while(Xm<=Xe&&Ym<=Ye)Fm=(Ym-1

5、20)*(Xe-100)-(Xm-100)*(Ye-120); if(Fm>=0)Xm=Xm+step;elseYm=Ym+step;lineto(Xm,Ym);gotoxy(55,8); printf("X%3.0f Y0 Z%3.0f",Xm-100,Ym-120);delay(1100);/* 圆插补部分的函数区 */void init_graph()/* 图形系统初始化 */int gdrive=DETECT,gmode;initgraph(&gdrive,&gmode,"");cleardevice();void acrr

6、oods()/* 屏幕中心坐标 */x0=getmaxx()/2;y0=getmaxy()/2;void draw_Base_circle() /* 画圆及写参数 */line(x0-200,y0,x0+200,y0); outtextxy(x0+220,y0,"Z");line(x0,y0-180,x0,y0+180); outtextxy(x0+10,y0+180,"X"); outtextxy(x0-10,y0+10,"O");circle(x0,y0,150);textcolor(YELLOW);directvideo=0;g

7、otoxy(46,2);cprintf("Circle start:X0 Y0 Z150"); gotoxy(46,3);cprintf("Circle end:X0 Y0 Z150");gotoxy(46,4);cprintf("Units :Pixel"); gotoxy(46,5);cprintf("Circle now:");void close_graph()/* 关图形系统 */3 / 14closegraph();void draw_cabu_circle(int sstep,int Director

8、y)/* 关键的圆插补函数 */int flag=0;float Fm,Xm,Ym; Xm=x0+150; Ym=y0;moveto(Xm,Ym); setcolor(RED);while(1) /* 分象限,顺圆和逆圆讨论 */Fm=(Xm-x0)*(Xm-x0)+(Ym-y0)*(Ym-y0)-150*150;/* 圆判断公式 */ if(Fm>=0)if(!Directory) /* 逆圆判断 */ if(Xm>=x0&&Ym<=y0)if(flag) break; /*if 语句判断象限,以下一样 */ else Xm=Xm-sstep; if(Xm&

9、lt;=x0&&Ym<=y0)flag=1; Ym=Ym+sstep; if(Xm<=x0&&Ym>=y0) Xm=Xm+sstep;if(Xm>=x0&&Ym>=y0) Ym=Ym-sstep;else /*it is Directory's else*/ if(Xm>x0&&Ym<y0)Ym=Ym+sstep; if(Xm<=x0&&Ym<=y0)Xm=Xm+sstep; if(Xm<x0&&Ym>y0) flag=1;

10、Ym=Ym-sstep; if(Xm>=x0&&Ym>=y0) if(flag) break;Xm=Xm-sstep; else /*it is Fm's else*/ if(!Directory) if(Xm>x0&&Ym<y0) 4 / 14if(flag) break;else Ym=Ym-sstep;if(Xm<=x0&&Ym<=y0)flag=1; Xm=Xm-sstep;if(Xm<=x0&&Ym>=y0)Ym=Ym+sstep;if(Xm>=x0&

11、&Ym>=y0)Xm=Xm+sstep;elseif(Xm>x0&&Ym<y0)Xm=Xm+sstep;if(Xm<=x0&&Ym<=y0)Ym=Ym-sstep;if(Xm<=x0&&Ym>=y0)flag=1; Xm=Xm-sstep; if(Xm>=x0&&Ym>=y0) if(flag) break;else Ym=Ym+sstep;lineto(Xm,Ym);gotoxy(58,5); printf("X%3.0f Y0 Z%3.0f ",

12、Ym-y0,Xm-x0); delay(800);void circle_demo(int Directory)/* 控制圆插补两次 */int i=0,sstep;init_graph();sleep(2);acrroods(&x0,&y0);for(i=0;i<2;i+)draw_Base_circle(150);if(i=0)sstep=6;draw_cabu_circle(sstep,Directory);elsesstep=1;draw_cabu_circle(sstep,Directory);5 / 14getch();cleardevice();setcol

13、or(WHITE);/* 圆插补部分的函数区结束 */main()/* 主函数负责写封面和函数调用 */int choice=0;init_graph();while(choice!=4)setfillstyle(1,RED); bar(200,30,400,80); setcolor(GREEN);settextstyle(3,0,10); outtextxy(220,50,"DEMO PROGRAM BY P.Y.F"); setcolor(WHITE);settextstyle(0,0,1);gotoxy(46,13);outtextxy(200,120,"

14、1. Line demo."); outtextxy(200,140,"2. Shun_Circle demo."); outtextxy(200,160,"3. Ni_Circle demo."); outtextxy(200,180,"4. Quit the program."); outtextxy(160,200,"Please enter your choice:"); scanf("%d",&choice);switch(choice)case 1: line_ca

15、bu();break;case 2: circle_demo(Ni_circle);break; case 3: circle_demo(Shun_circle);break; case 4: break;default: printf("nChoice wrong,try again!");close_graph();6 / 142 逐点比较法圆弧插补 VB 源程序Sub 偏差计算 ()偏差 = Sqr(x 动点 - x 圆心 ) 2 + (z 动点 - z 圆心 ) 2) - R End Sub Sub 插补 ()x 动点 = x 起点 : z 动点 = z 起点 :

16、动点象限判别 xx: Select Case 象限标志 Case 1: 单步连续判断If 顺逆标志 = "顺" Then '第一象限插补Do Until (x 动点 - x 终点 ) = 0 And (z 动点 - z 终点 ) = 0 If 偏差 >= 0 Thenx 动点 = x 动点 - 1:Line -Step(0, -x 步长 ), vbRedElse z 动点 = z 动点 + 1: Line -Step(z 步长 , 0), vbRedEnd If 偏差计算 动点象限判别 If 象限标志 <> 1 Then GoTo xx End I

17、f 单步连续判断LoopElseIf 顺逆标志 = " 逆 " ThenDo Until (x 动点 - x 终点) = 0 And (z 动点 - z 终点) = 0 If 偏差 >= 0 Then z 动点 = z 动点 - 1: Line -Step(-z 步长 , 0), vbRedElse x 动点 = x 动点 + 1: Line -Step(0, x 步长 ), vbRedEnd If DoEvents 偏差计算 动点象限判别 If 象限标志 <> 1 Then GoTo xxEnd IfLoopEnd If Case 2: 单步连续判断If

18、 顺逆标志 = "顺" Then '第二象限插补Do Until (x 动点 - x 终点) = 0 And (z 动点 - z 终点) = 0 If 偏差 >= 0 Then z 动点 = z 动点 - 1: Line -Step(-z 步长 , 0), vbRedElsex 动点 = x 动点 - 1:Line -Step(0, -x 步长 ), vbRedEnd If 偏差计算 动点象限判别 If 象限标志 <> 2 Then GoTo xx End IfLoopElseIf 顺逆标志 = " 逆 " ThenDo Unt

19、il (x 动点 - x 终点) = 0 And (z 动点 - z 终点) = 0 If 偏差 >= 0 Thenx 动点 = x 动点 + 1:Line -Step(0, x 步长 ), vbRedElse z 动点 = z 动点 + 1: Line -Step(z 步长 , 0), vbRedEnd If 偏差计算 动点象限判别 If 象限标志 <> 2 Then GoTo xx End IfLoopEnd IfCase 3: 单步连续判断If 顺逆标志 = "顺" Then '第三象限插补Do Until (x 动点 - x 终点) = 0

20、 And (z 动点 - z 终点) = 0 If 偏差 >= 0 Thenx 动点 = x 动点 + 1:Line -Step(0, x 步长 ), vbRedElse z 动点 = z 动点 - 1: Line -Step(-z 步长 , 0), vbRedEnd If DoEvents 偏差计算 动点象限判别If 象限标志 <> 3 Then GoTo xxEnd IfLoopElseIf 顺逆标志 = " 逆 " ThenDo Until (x 动点 - x 终点) = 0 And (z 动点 - z 终点) = 0 If 偏差 >= 0 T

21、hen z 动点 = z 动点 + 1:Line -Step(z 步长 , 0), vbRedElsex 动点 = x 动点 - 1:Line -Step(0, -x 步长 ), vbRedEnd If 偏差计算 动点象限判别 If 象限标志 <> 3 Then GoTo xx End IfLoopEnd IfCase 4: 单步连续判断If 顺逆标志 = "顺" Then '第三象限插补Do Until (x 动点 - x 终点) = 0 And (z 动点 - z 终点) = 0 If 偏差 >= 0 Then z 动点 = z 动点 + 1:

22、 Line -Step(z 步长 , 0), vbRedElsex 动点 = x 动点 + 1:Line -Step(0, x 步长 ), vbRedEnd If 偏差计算 动点象限判别 If 象限标志 <> 4 Then GoTo xxEnd IfLoopElseIf 顺逆标志 = " 逆 " ThenDo Until (x 动点 - x 终点) = 0 And (z 动点 - z 终点) = 0 If 偏差 >= 0 Thenx 动点 = x 动点 - 1:Line -Step(0, -x 步长 ), vbRedElse z 动点 = z 动点 - 1

23、: Line -Step(-z 步长 , 0), vbRedEnd If 偏差计算 动点象限判别If 象限标志 <> 4 Then GoTo xxEnd IfLoopEnd IfEnd SelectEnd Sub9 / 143 逐点比较法直线插补 VB 源程序Sub 偏差计算 ()偏差 = Abs(x终点)X Z动点-x 动点 X Abs(z终点)End SubSub 插补 ()Dim c As Integer10 / 14# / 14Select Case 象限标志Case 1:' 第一象限插补Do Until x 动点 + z 动点 >= 总步数If 偏差 >

24、;= 0 Thenx 动点 = x 动点 + 1:Line -Step(0, x 步长 ), vbRedElsez 动点 = z 动点 + 1:Line -Step(z 步长 , 0), vbRedEnd If 偏差计算LoopCase 2:' 第二象限插补c = x 终点: x 终点= z 终点: z 终点= -cc = x 步长 : x 步长 = z 步长: z 步长 = -cDo Until x 动点 + z 动点 >= 总步数If 偏差 >= 0 Thenx 动点 = x 动点 + 1:Line -Step(x步长 , 0), vbRedElsez 动点 = z 动

25、点 + 1:Line -Step(0, z步长 ), vbRedEnd If偏差计算LoopCase 3:' 第三象限插补x 步长 = -x 步长 : z 步长 = -z 步长 Do Until x 动点 + z 动点 >= 总步数 If 偏差 >= 0 Thenx 动点 = x 动点 + 1:Line -Step(0, x 步长 ), vbRedElsez 动点 = z 动点 + 1:Line -Step(z 步长 , 0), vbRedEnd If偏差计算LoopCase 4:' 第四象限插补c = x 终点 : x 终点 = -z 终点: z 终点 = c c

26、 = x 步长 : x 步长 = -z 步长: z 步长 = c Do Until x 动点 + z 动点 >= 总步数 If 偏差 >= 0 Then步长 , 0),步长 ),x 动点 = x 动点 + 1: Line -Step(x vbRedElsez 动点 = z 动点 + 1: Line -Step(0, z vbRedEnd If偏差计算LoopEnd SelectEnd Sub11 / 144 时间分割法直线插补参考 VB 程序Sub 插补 ()Dim l, K, a, B, f1, tx 动点对起点 = 0: z 动点对起点 = 0fl = f 10: t = Ts / 60000l = Sqr(x终点对起点A 2 + z终点对起点 A 2)K = flt>/ la = Sqr(x动点对起点 -x终点对起点)a 2 + (z动点对起点-z终点对起点)a 2)x步长 =K *终点对起点:z步长 =K 邃终点对起点:B = Sqr(z 步长 A 2 + x 步长 A 2)Do Until a <= B / 2x 动点对起点 =

温馨提示

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

评论

0/150

提交评论