【问题标题】:Get circles x and y center获取圆 x 和 y 中心
【发布时间】:2022-01-05 17:43:11
【问题描述】:

我的目标是从 dxf 文件中获取所有圈子,其中包含 3 个信息,例如:circumference, X center, Y center。到目前为止,我能够得到圆周。我怎样才能得到Y & X?这是我当前的代码:

import sys
import ezdxf

doc = ezdxf.readfile("File.dxf")
msp = doc.modelspace()

for e in msp:    
    if e.dxftype() == 'CIRCLE':
            dc = 2 * math.pi * e.dxf.radius
            print('circumference: ' + str(dc))

【问题讨论】:

    标签: python dxf ezdxf


    【解决方案1】:

    圆的中心是e.dxf.center 作为对象坐标系 (OCS) 中的Vec3 对象。如果挤出向量为 (0, 0, 1),则 OCS 就是 WCS,大多数情况下都是 2D 实体的情况。

    有时镜像的 2D 实体在这种情况下有一个反向挤压向量 (0, 0, -1),需要将 OCS 坐标转换为 WCS 坐标:

    for e in msp.query("CIRCLE"):
        ocs = e.ocs()
        wcs_center = ocs.to_wcs(e.dxf.center)
        x = wcs_center.x
        y = wcs_center.y
    

    【讨论】:

      【解决方案2】:

      查看文档,似乎 Circle 有一个 'center' 属性,所以

      e.center
      

      应该给你坐标

      https://ezdxf.readthedocs.io/en/stable/dxfentities/circle.html

      【讨论】:

        猜你喜欢
        • 2011-07-22
        • 1970-01-01
        • 2011-08-02
        • 2016-09-17
        • 2019-09-03
        • 2022-11-13
        • 1970-01-01
        • 2023-01-25
        • 1970-01-01
        相关资源
        最近更新 更多