博客
关于我
autocadR12的格式分析(一)
阅读量:753 次
发布时间:2019-03-22

本文共 2625 字,大约阅读时间需要 8 分钟。

AutoCAD R12的直线和圆格式剖析及代码实现

1. 直线格式

在AutoCAD R12中,直线的数据存储格式采用DXF文件格式,其中直线的 RECORD 8 0 XPICLINES 类型保存在线段信息。具体来说,直线记录的字段包括:

  • 10:x坐标
  • 20:y坐标
  • 11:x2坐标
  • 21:y2坐标
  • 73:插画方向参数
  • 8 0:线宽
  • 62 xx:颜色代码

以下是典型的直线数据示例:

0 SECTION 2 ENTITIES 0LINE 8 0 XPICLINES 0.1862 110 3.000000 20 3.000000 11 5.000000 21 5.000000 0 ENDSEC 0 EOF

2. 圆的格式

在AutoCAD R12中,圆的数据格式同样使用DXF文件格式。相同于直线,圆的 RECORD 8 0 XPICLINES 类型保存圆的信息。然而,圆的字段增加了:

  • 40:半径

因此,圆的记录格式如下:

0 SECTION 2 ENTITIES 0CIRCLE 8 0 XPICLINES 0.1862 110 3.000000 20 3.000000 40 3.000000 0 ENDSEC 0 EOF

需要注意的是,与直线相比,圆记录中缺少某些点序列字段(如73和74),因为圆是通过中心点和半径直接定义的。

3. 代码实现

为了实现有不同颜色和宽度的直线和圆,我们可以编写C语言程序来生成符合DXF格式的代码。以下是实现代码:

#include 
#include
#include
struct Points { char row[10]; // 定义10行 double x, y, z; // 定义点的三个坐标};void LineDXFr(FILE *fp, struct Points start, struct Points end) { fprintf(fp, "0\nLINE\n"); fprintf(fp, "8\n0.18\n"); // 线宽0.18mm fprintf(fp, "62\n1\n"); // 红色线 fprintf(fp, "10\n%f\n20\n%f\n11\n%f\n21\n%f\n", start.x, start.y, end.x, end.y);}void CircleDXF(FILE *fp, struct Points center, double radius) { fprintf(fp, "0\nCIRCLE\n"); fprintf(fp, "8\n0.18\n"); // 线宽0.18mm fprintf(fp, "62\n1\n"); // 红色圆 fprintf(fp, "10\n%f\n20\n%f\n40\n%f\n", center.x, center.y, radius);}void LineDXFg(FILE *fp, struct Points start, struct Points end) { fprintf(fp, "0\nLINE\n"); fprintf(fp, "8\n0.18\n"); // 线宽0.18mm fprintf(fp, "62\n3\n"); // 绿色线 fprintf(fp, "10\n%f\n20\n%f\n11\n%f\n21\n%f\n", start.x, start.y, end.x, end.y);}void LineDXFy(FILE *fp, struct Points start, struct Points end) { fprintf(fp, "0\nLINE\n"); fprintf(fp, "8\n0.18\n"); // 线宽0.18mm fprintf(fp, "62\n2\n"); // 黄色线 fprintf(fp, "10\n%f\n20\n%f\n11\n%f\n21\n%f\n", start.x, start.y, end.x, end.y);}int main() { struct Points po1 = {"1", 3, 3, 3}; struct Points po2 = {"2", 5, 7, 5}; struct Points po3 = {"3", 8, 9, 8}; struct Points po4 = {"4", 10, 13, 10}; FILE *fp; fp = fopen("lineall3d.dxf", "w"); if (fp == NULL) { printf("无法打开文件 !\n"); return; } fprintf(fp, "0\nSECTION\n"); fprintf(fp, "2\nENTITIES\n"); // 画红色的直线 LineDXFr(fp, po1, po2); // 画绿色的直线 LineDXFg(fp, po3, po4); // 画黄色的直线 LineDXFy(fp, po2, po3); // 画红色的圆 CircleDXF(fp, po1, 3); fprintf(fp, "0\nENDSEC\n"); fprintf(fp, "0\nEOF"); fclose(fp); return 0;}

4. 代码说明

  • LineDXFr 函数绘制红色圆线,使用指定的线宽。
  • CircleDXF 函数绘制红色圆,中心坐标和半径由参数提供。
  • LineDXFgLineDXFy 分别绘制绿色和黄色的直线。
  • 主函数中包含了创建点结构和文件操作,同时调用各个绘制函数,生成最终的DXF文件。

这种代码可以根据需求调整颜色和线宽,而无需手动操作,适合自动化处理需要生成符合特定格式的几何图形的场景。

转载地址:http://bkgwk.baihongyu.com/

你可能感兴趣的文章
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>