逐点比较法插补c语言程序源代码
逐点比较法插补c语言程序源代码
#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()