前情回顾
在上一节的优快云中:
实现了直线和圆弧的绘制。
但是不能移动和缩放。

还需要一个方法,对这些数据进行组织。
正文
组织图元
铺垫:
怎么组织图元呢?
也许可以参考画家算法的处理顺序。

也许还能借用python的二维列表
根据相交关系,来组织零散的图元。
怎么判断直线与直线相交?
——未知
怎么判断圆弧与圆弧相交?
——未知
怎么判断直线与圆弧相交?
——点到直线距离公式

计算两点之间的距离,可能会用到numpy:
https://www.runoob.com/numpy/numpy-tutorial.html
https://www.runoob.com/numpy/numpy-tutorial.html 然后,怎么重组?重组以后存哪?用什么数据结构存?
暂定是这样:

二维list里,得能判断每个元素具体是什么图元类。应该可以借助type实现:
#读取
dxf = dxfgrabber.readfile(inputFilePath)
lineNum=0
arcNum=0
for e in dxf.entities:
if e.dxftype == 'LINE':
LINELIST.append(Line(lineNum,e.start,e.end))
lineNum+=1
elif e.dxftype=='ARC':
ARCLIST.append(Arc(arcNum,e.center,e.radius,e.start_angle,e.end_angle))
arcNum+=1
#图元重组
#获取种类
if Line==type(LINELIST[0]):
print("is line")
if Arc==type(ARCLIST[0]):
print("is arc")
二维list,也许应该叫嵌套list:
https://www.runoob.com/python3/python3-list.html
https://www.runoob.com/python3/python3-list.html
测试:
a=[1,2,4]
b=[4,5,6]
x=[]
x.append(a)
x.append(b)
print(x[0])
print(x[1])
c=['x','y','x']
x.append(c)
print(x[2])
print(x[2][0])
输出结果
python下如何使用switch-case——python3.10以上才能用。3.7不行。
#python-switch-case
i=10
match i:
case 10:
pass
case 11:
pass
怎么处理OpenGL的鼠标事件?比如,点击,按下并移动?
https://cuiqingcai.com/1776.html
https://cuiqingcai.com/1776.html</

本文介绍了如何在Python中通过dxfgrabber库读取DXF文件,实现直线、圆弧的绘制,并通过算法组织图元,涉及相交测试和数据结构的选择,如使用二维列表、嵌套列表和集合。通过`intersectionTest`函数,图元被分组成不相交的集群。

最低0.47元/天 解锁文章
1268

被折叠的 条评论
为什么被折叠?



