当前位置:文档之家› 直线插补和圆弧插补

直线插补和圆弧插补

?直线插补程序设计 C语言

#include "stdio.h"
int i,X,Y,X0,Y0,Xe,Ye,F,N;
int a[30][2];

void main()
{
int m;
int menu();//函数声明
void yi();
void er();
void san();
void si();
void te();
void shuchu();

m=menu();
a[0][0]=X0;
a[0][1]=Y0;

switch(m)
{
case 1:yi();shuchu();break;
case 2:er();shuchu();break;
case 3:san();shuchu();break;
case 4:si();shuchu();break;
case 5:te();shuchu();break;
default:printf("无法插补\n");?
}
}

int menu()
{
int t;
printf("输入起点坐标\n");
scanf("%d,%d",&X0,&Y0);
printf("输入终点坐标\n");
scanf("%d,%d",&Xe,&Ye);?

if (Xe>=X0&&Ye>=Y0)
t=1;
else if (Xe<=X0&&Ye>=Y0)
t=2;
else if (Xe<=X0&&Ye<=Y0)
t=3;
else if (Xe>=X0&&Ye<=Y0)
t=4;
else if (Xe==X0&&((Ye>Y0&&Y0>=0)||(Yet=5;
else
t=6;
return(t);
}

void yi()
{
F=0;
N=Xe-X0+Ye-Y0;
X=X0;
Y=Y0;

for(i=1;i<=N;i++)
{
if(F>=0)
{
X++;
a[i][0]=X;
a[i][1]=Y;
F-=Ye-Y0;
}else
{
Y++;
a[i][0]=X;
a[i][1]=Y;
F+=Xe-X0;
}
}
}

void er()
{
F=0;
N=X0-Xe+Ye-Y0;
X=X0;
Y=Y0;

for(i=1;i<=N;i++)
{
if(F>=0)
{
X--;
a[i][0]=X;
a[i][1]=Y;
F-=Ye-Y0;
}else
{
Y++;
a[i][0]=X;
a[i][1]=Y;
F+=X0-Xe;
}
}
}

void san()
{
F=0;
N=X0-Xe+Y0-Ye;
X=X0;
Y=Y0;

for(i=1;i<=N;i++)
{
if(F>=0)
{
X--;
a[i][0]=X;
a[i][1]=Y;
F-=Y0-Ye;
}else
{
Y--;
a[i][0]=X;
a[i][1]=Y;
F+=X0-Xe;
}
}
}

void si()
{
F=0;
N=Xe-X0+Y0-Ye;
X=X0;
Y=Y0;

for(i=1;i<=N;i++)
{
if(F>=0)
{
X++;
a[i][0]=X;
a[i][1]=Y;
F-=Y0-Ye;
}else
{
Y--;
a[i][0]=X;
a[i][1]=Y;
F+=Xe-X0;
}
}
}

void te()
{
N=Ye-Y0;

for(i=1;i<=N;i++)
{
if(Ye>0)
{
Y++;
a[i][0]=X;
a[i][1]=Y;
}else if(Ye<0)
{
Y--;
a[i][0]=X;
a[i][1]=Y;
}
}
}

void shuchu()
{
for(i=0;i<=N;i++)
{
printf("%d ",i);
printf("%d,%d\n",a[i][0],a[i][1]);
}
}


程序结果?
例如?起点(0,0)终点(6,4)
步数 坐标?
1 1,0
2 1,1
3 2,1
4 2,2
5 3,2
6 4,2
7 4,3
8 5,3
9 6,3
10 6,4



圆弧插补程序 C语言



#include?"stdio.h"
#include?"math.h"?
int?X0,Y0,X1,Y1,X2,Y2,X3,Y3,X4,Y4;
int?i=1,r,f,s;
void?main()
{?
int?m;
int?menu();
void?yishun();
void?yini();
void?ershun();
void?erni();
void?sanshun();
void?sanni();
void?sishun();
void?sini();
void?shuchu();

m=menu();

switch(m)
{
case?1:yishun();break;
case?2:yini();break;
case?3:ershun();break;
case?4:yini();break;
case?5:sanshun();break;
case?6:yini();break;
case?7:sishun();break;
case?8:yini();break;
default:printf("无法插补\n");
}
}

int?menu()
{
int?t;
printf

("输入原点坐标\n");
scanf("%d,%d",&X0,&Y0);
printf("输入起点坐标\n");
scanf("%d,%d",&X3,&Y3);
printf("输入终点坐标\n");
scanf("%d,%d",&X4,&Y4);
printf("1:顺时针圆弧\n");
printf("2:逆时针圆弧\n");
scanf("%d",&s);

X1=X3-X0;?
Y1=Y3-Y0;
X2=X4-X0;
Y2=Y4-Y0;

r=X1*X1+Y1*Y1;
if?(X1>=0&&Y1>0&&s==1)
t=1;
else?if?(X1>0&&Y1>=0&&s==2)
t=2;?
else if?(X1<0&&Y1>=0&&s==1)
t=3;?
else?if?(X1<=0&&Y1<0&&s==2)
t=4;
else?if?(X1<=0&&Y1<0&&s==1)
t=5;?
else?if?(X1<0&&Y1<=0&&s==2)
t=6;
else?if?(X1>0&&Y1<=0&&s==1)
t=7;?
else?if?(X1>=0&&Y1<0&&s==2)
t=8;
else
t=9;?
return(t);
}

void?yishun()
{
do
{
f=X1*X1+Y1*Y1-r;
if(f>=0)
{
Y1--;
f-=2*Y1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}else
{
X1++;
f+=2*X1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}
}?
while(Y1!=0&&(X1!=X2||Y1!=Y2));
if(Y1==0)
{
void?sishun();
sishun();
}
}

void?yini()
{
do
{
f=X1*X1+Y1*Y1-r;
if(f>=0)
{
X1--;
f-=2*X1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}else
{
Y1++;
f+=2*Y1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}
}?
while(X1!=0&&(X1!=X2||Y1!=Y2));

if(X1==0)
{
void?erni();
erni();
}
}

void?ershun()
{
do
{
f=X1*X1+Y1*Y1-r;
if(f>=0)
{
X1++;
f+=2*X1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}else
{
Y1++;
f+=2*Y1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}
}
while(X1!=0&&(X1!=X2||Y1!=Y2));

if(X1==0)
{
void?yishun();
yishun();
}
}

void?erni()
{
do
{
f=X1*X1+Y1*Y1-r;
if(f>=0)
{
Y1--;
f-=2*Y1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}else
{
X1--;
f-=2*X1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}
}
while(Y1!=0&&(X1!=X2||Y1!=Y2));

if(Y1==0)
{
void?sanni();
sanni();
}
}

void?sanshun()
{
do
{
f=X1*X1+Y1*Y1-r;
if(f>=0)
{
Y1++;
f+=2*Y1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}else
{
X1--;
f-=2*X1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}
}
while(Y1!=0&&(X1!=X2||Y1!=Y2));

if(Y1==0)
{
void?ershun();
ershun();
}
}

void?sanni()
{
do
{
f=X1*X1+Y1*Y1-r;
if(f>=0)
{
X1++;
f+=2*X1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}else
{
Y1--;
f+=2*Y1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}
}
while(X1!=0&&(X1!=X2||Y1!=Y2));

if(X1==0)
{
void?sini();
sini();
}
}
void?sishun()?
{
do
{
f=X1*X1+Y1*Y1-r;
if(f>=0)
{
X1--;
f-=2*X1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}else
{
Y1--;
f-=2*Y1+1;
i++;

printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}
}
while(X1!=0&&(X1!=X2||Y1!=Y2));

if(X1==0)
{
void?sanshun();
sanshun();
}
}

void?sini()
{
do
{
f=X1*X1+Y1*Y1-r;
if(f>=0)
{
Y1++;
f+=2*Y1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}else
{
X1++;
f+=2*X1+1;
i++;
printf("%d?",i);
printf("%d,%d\n",X1,Y1);
}
}
while(Y1!=0&&(X1!=X2||Y1!=Y2));

if(Y1==0)
{
void?yini();
yini();
}
}


程序结果?

例如?圆心(0,0)起点(4,3)终点(4,3)?
步数 坐标

0 4,3
1 3,3
2 3,4
3 2,4
4 2,5
5 1,5
6 0,5
7 0,4
8 -1,4
9 -2,4
10 -3,4
11 -3,3
12 -4,3
13 -4,2
14 -5,2
15 -5,1
16 -5,0
17 -4,0
18 -4,-1
19 -4,-2
20 -4,-3
21 -3,3
22 -3,-4
23 -2,-4
24 -2,-5
25 -1,-5
26 0,-5
27 0,-4
28 1,-4
29 2,-4
30 3,-4
31 3,-3
32 4,-3
33 4,-2
34 5,-2
35 5,-1
36 5,0
37 4,0
38 4,1
39 4,2
40 4,3

相关主题
文本预览
相关文档 最新文档