- 积分
- 172
- 明经币
- 个
- 注册时间
- 2010-12-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
谁有比较完整的 基于 dxf 用 C语言 编写dxf文件的各个模块 例如
#include "stdio.h"
#include "string.h"
FILE *fp;
/*接口程序*/
/*建立一个DXF新文件,并生成实体段标题段的函数*/
begin()
{
char fname[50];
printf("Enter DXF file name:\n");
scanf("%s",fname);
strcat(fname,".dxf");
fp=fopen(fname,"w+");
fprintf(fp," 0\nSECTION\n 2\nENTITIES\n");
}
/*写直线实体*/
line(float xs,float ys,float xe,float ye)
{
fprintf(fp," 0\nLINE\n 8\n0\n");
fprintf(fp," 10\n%f\n",xs);
fprintf(fp," 20\n%f\n",ys);
fprintf(fp," 30\n0.0\n");
fprintf(fp," 11\n%f\n",xe);
fprintf(fp," 21\n%f\n",ye);
fprintf(fp," 31\n0.0\n");
}
/*写圆实体函数,已知圆心和半径*/
circle(float xc,float yc ,float r)
{
fprintf(fp," 0\nCIRCLE\n 8\n0\n");
fprintf(fp," 10\n%f\n",xc);
fprintf(fp," 20\n%f\n",yc);
fprintf(fp," 30\n0.0\n");
fprintf(fp," 40\n%f\n",r);
}
/*写圆弧实体函数,已知圆心,半径,起始角和终止角*/
arc(float xc,float yc,float r,float ang1, float ang2)
{
fprintf(fp," 0\nARC\n 8\n0\n");
fprintf(fp," 10\n%f\n",xc);
fprintf(fp," 20\n%f\n",yc);
fprintf(fp," 30\n0.0\n");
fprintf(fp," 40\n%f\n",r);
fprintf(fp," 50\n%f\n",ang1);
fprintf(fp," 51\n%f\n",ang2);
}
/*生成段尾和文件结束符号的函数,并关闭DXF文件*/
ending()
{
fprintf(fp," 0\nENDSEC\n 0\nEOF\n");
fclose(fp);
}
main()
{
float x0=0,y0=0,b=50,h=70,d=25;
// printf("Enter x0,y0,b,h,d:\n");
// scanf("%f,%f,%f,%f,%f",&x0,&y0,&b,&h,&d);
begin();
line(x0,y0,x0+b,y0);
line(x0+b,y0,x0+b,y0+h);
arc(x0+b/2,y0+h,b/2,0,180);
line(x0,y0+h,x0,y0);
circle(x0+b/2,y0+h,d/2);
ending();
}
有的话分享一下吧
|
|