首页 > 文章 > 数控插补

逐点比较法插补c语言程序源代码

       2023-05-29 来源:互联网热度:76评论:0
    广告
    核心提示:#include conio.h #include graphics.h #include process.h #define Ni_circle 0 #define Shun_circle 1 void init_graph(); void draw_Base_circle(); void draw_cabu_circle(); void close_graph(); void acrroods(); static float x0,y0; void line_cabu(), draw_line(),d

   #include "conio.h"

   #include "graphics.h"

   #include "process.h"

   #define  Ni_circle 0

   #define  Shun_circle 1

   void init_graph();

   void draw_base_circle();

   void 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,"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:X0   Y0 Z0 ");

     gotoxy(45,6);  cprintf("Line to  :X500 Y0 Z330");

     gotoxy(45,7);  cprintf("Units    :Pixel");

     gotoxy(45,8);  cprintf("Line  now:");

   }

   void draw_line_cabu(int step)

    {

      int Xe=600,Ye=450;

      float Fm,Xm=100,Ym=120;

      setcolor(RED);

      moveto(Xm,Ym);

      while(Xm<=Xe&&Ym<=Ye)

           {

               Fm=(Ym-120)*(Xe-100)-(Xm-100)*(Ye-120);

               if(Fm>=0)

                        Xm=Xm+step;

               else

                        Ym=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 acrroods()              

    {

       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;

          gotoxy(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()            

   {

     closegraph();

   }

   void draw_cabu_circle(int sstep,int Directory)

   {

     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;  

                            else       Xm=Xm-sstep;

                        }

                    if(Xm<=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  {                   

                      if(Xm>x0&&Ym<y0)

                                        Ym=Ym+sstep;

                     if(Xm<=x0&&Ym<=y0)

                                         Xm=Xm+sstep;

                     if(Xm<x0&&Ym>y0) {

                            flag=1;     Ym=Ym-sstep;}

                     if(Xm>=x0&&Ym>=y0) {

                             if(flag)  break;

                                          Xm=Xm-sstep;}

                      }

               }

           else{       

                if(!Directory) {

                     if(Xm>x0&&Ym<y0)

                       {

                          if(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&&Ym>=y0)

                                          Xm=Xm+sstep;

                                      }

                else{

                      if(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     ",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);}

       else{

               sstep=1;

            draw_cabu_circle(sstep,Directory);}

       getch();

       cleardevice();

       setcolor(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);

           outtextxy(200,120,"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:");   gotoxy(46,13);

           scanf("%d",&choice);

    switch(choice)

          {

            case 1:  line_cabu();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();

   }


  • 信息来源:互联网
  • 版权声明:本站部分内容文章及图片来自互联网或自媒体,版权归属于原作者。如内容、图片有任何版权侵权问题,请联系我们处理,我们将在第一时间删除内容。
  • 免责声明:数控信息网发布此文目的在于促进信息交流,不存在盈利性目的,此文观点与本站立场无关,不承担任何责任。未经证实的信息仅供参考,据此操作风险自担。
  • 文本链接:https://skxx.site/news/show-4388.html
  • 小黑共发布427篇

  • 生成海报

    分享到微信

    分享到QQ

    更多分享

0相关评论
  • 小黑
这小子很懒什么也没留下。
  • 文章427
  • 浏览3216
  • 收藏0
  • 粉丝 0
    推荐图文