| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 413 人关注过本帖
标题:[讨论]关于画弧?
只看楼主 加入收藏
wlf
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-5-26
收藏
 问题点数:0 回复次数:0 
[讨论]关于画弧?

下面是用C从数控程序中提取坐标数据画图,又一些问题,特别是画弧部分和自己想得到的不一样,请高手改一下,附件是一小段数控程序
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
FILE *fp;
char file[10],ch,str[4];
double a[100][7];
int flag[100];
int i=0,j=1;
double arc1,arc2,f1,f2;
int s;
int graphdriver=VGA,graphmode=VGAHI;
/* registerbgidriver(EGAVGA_driver); */
initgraph(&graphdriver,&graphmode,"");
printf("Enter the file name:\n");
scanf("%s",file);
if ((fp=fopen(file,"r"))==NULL)
{printf ("cannot open this file\n");
exit(0);
}
ch=fgetc(fp);
while (ch!=EOF)
{while ((ch=fgetc(fp))=='G')
{
fgets (str,3,fp);
if (strcmp(str,"01")==0) {i++;flag[i]=1;}
else if (strcmp(str,"02")==0) {i++;flag[i]=2;}
else if (strcmp(str,"03")==0) {i++;flag[i]=3;}
else if (strcmp(str,"00")==0) {i++;flag[i]=0;}
else break;
ch=fgetc(fp);
while (ch!='N' && ch!=EOF)
{int p=0;
if (ch=='X')
{
char st1[10]={'0'};
a[i][j]=a[i-1][j];
ch=fgetc(fp);
while('0'<=ch && ch<='9' || ch=='.' || ch=='-' )
{
st1[p]=ch;
ch=fgetc(fp); p++;
}
a[i][j]=atof(st1);
printf("%f",a[i][j]);getch();
}
if (ch=='Y')
{
char st2[10]={'0'};
int j=2;
a[i][j]=a[i-1][j];
ch=fgetc(fp);
while('0'<=ch && ch<='9' || ch=='.' || ch=='-' )
{
st2[p]=ch;
ch=fgetc(fp);p++;
}
a[i][j]=atof(st2);
printf("%f",a[i][j]);getch();
}
if (ch=='Z')
{
int j=3;
char st3[10]={'0'};
a[i][j]=a[i-1][j];
ch=fgetc(fp);
while('0'<= ch && ch<='9' || ch=='.' || ch=='-')
{
st3[p]=ch;
ch=fgetc(fp);p++;
}
a[i][j]=atof(st3);
printf("%f",a[i][j]);getch();
}
if (ch=='I')
{
char st4[10]={'0'};
int j=4;
ch=fgetc(fp);
while('0'<= ch && ch<='9' || ch=='.' ||ch=='-')
{
st4[p]=ch;
ch=fgetc(fp);p++;
}
a[i][j]=atof(st4);
printf("%f",a[i][j]);getch();
}
if (ch=='J')
{
int j=5;
char st5[10]={'0'};
ch=fgetc(fp);
while('0'<= ch && ch<='9' || ch=='.' ||ch=='-')
{
st5[p]=ch;
ch=fgetc(fp);p++;
}
a[i][j]=atof(st5);
printf("%f",a[i][j]);getch();
}
if (ch=='K')
{
int j=6;
char st6[10]={'0'};
ch=fgetc(fp);
while('0'<= ch && ch<='9' || ch=='.' ||ch=='-')
{
st6[p]=ch;
ch=fgetc(fp);p++;
}
a[i][j]=atof(st6);
printf("%f",a[i][j]);getch();
}

ch=fgetc(fp);
}
}
}
cleardevice();
setcolor(4);
setbkcolor(1);
/*printf("%d\n",i); */
for(s=1;s<=i;s++)
{
/* printf("%d\n",flag[s]); */
if(flag[s]=0) moveto(a[s][1],a[s][2]);getch();
if(flag[s]=1) line(a[s-1][1],a[s-1][2],a[s][1],a[s][2]);getch;
if(flag[s]=3)
{
arc1=atan2(a[s][5],a[s][4]);
f1=a[s][5]+a[s-1][2]-a[s][2];
f2=a[s][4]+a[s-1][1]-a[s][1];
arc2=atan2(f1,f2);
arc((a[s][4]+a[s-1][1]),(a[s][5]+a[s-1][2]),arc1*180/3.1415926,arc2*180/3.1415926,sqrt(a[s][4]*a[s][4]+a[s][5]*a[s][5]));
getch();
}
if(flag[s]=2)
{
arc1=atan2(a[s][5],a[s][4]);
f1=a[s][5]+a[s-1][2]-a[s][2];
f2=a[s][4]+a[s-1][1]-a[s][1];
arc2=atan2(f1,f2);
arc((a[s][4]+a[s-1][1]),(a[s][5]+a[s-1][2]),arc1*180/3.1415926,arc2*180/3.1415926,sqrt(a[s][4]*a[s][4]+a[s][5]*a[s][5]));
getch();
}
}
getch();
closegraph();
}

0uQ7AHpT.txt (159 Bytes) [讨论]关于画弧?


搜索更多相关主题的帖子: 数控 include double 
2006-06-02 11:13
快速回复:[讨论]关于画弧?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035062 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved