- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 dxf 文件中获取形状的尺寸。我尝试查看 dxfgrabber 和 ezdxf 库,我采用了最低点和最高点来获取尺寸,但结果是错误的。使用 dxfgrabber:
import dxfgrabber
import numpy as np
import sys
dxf = dxfgrabber.readfile(sys.argv[1])
shapes = dxf.entities.get_entities()
minX, maxX, minY, maxY = 999999,0,999999,0
for shape in shapes:
print('dxftype', shape.dxftype)
if shape.dxftype == 'LINE':
x, y = shape.start[0], shape.start[1]
if x < minX:
minX = x
if y < minY:
minY = y
if x >= maxX:
maxX = x
if y >= maxY:
maxY = y
x, y = shape.end[0], shape.end[1]
if x < minX:
minX = x
if y < minY:
minY = y
if x >= maxX:
maxX = x
if y >= maxY:
maxY = y
if shape.dxftype == 'ARC':
x, y = shape.center[0], shape.center[1]
if x < minX:
minX = x
if y < minY:
minY = y
if x >= maxX:
maxX = x
if y >= maxY:
maxY = y
print('minX', minX, 'minY', minY)
print('maxX', maxX, 'maxY', maxY)
print('x1', 0, 'y1', 0)
print('x2', maxX-minX, 'y2', maxY-minY)
使用 ezdxf:
modelspace = dwg.modelspace()
for e in modelspace:
if e.dxftype() == 'LINE':
print("start point: ", e.dxf.start)
print("end point: ", e.dxf.end)
if e.dxftype() == 'ARC':
print("ARC on layer: ", e.dxf.layer)
print("center point ", e.dxf.center)
然后手动取了minX minY maxX maxY。
是否有任何计算方法或任何现有库来获取尺寸?
最佳答案
And manually took the
minX
,minY
,maxX
,maxY
.
使用元素的边界范围是不正确的。如果 LINE 不是垂直或水平的,则尤其如此。一旦处于轮换,您的逻辑就会失败。
Is there any way of calculating, or any existing libraries to get the dimensions ?
我无法具体评论您正在使用的软件库。它们可能只读取 DXF 文件,不提供其他功能。
看来您正在处理二维数据。在你的问题中显示:
对于 LINE
元素,这是一个示例(在 Visual Basic for Applications 中):
Public Function Get2DLength(aryPoint1 As Variant, _
aryPoint2 As Variant) As Double
Dim dDeltaX As Double
Dim dDeltaY As Double
dDeltaX = aryPoint2(0) - aryPoint1(0)
dDeltaY = aryPoint2(1) - aryPoint1(1)
Get2DLength = Sqr((dDeltaX * dDeltaX) + (dDeltaY * dDeltaY))
End Function
如果您正在处理 3D 数据,则通过引入 dDeltaZ
来扩展该方法。
您应该能够将其移植到您的环境中。恐怕 A 不能评论 ARC
元素。
通过快速谷歌,我找到了一个相关的 StackOverflow question其中提供了计算弧长的公式:
Arc Length = Radius * (Angle In Radian)
有一个二级link在评论中提供更多信息。
所以您现在应该能够准确计算出您的长度。
关于python-3.x - 如何在 python 中的 DXF 中查找形状的尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49151320/
我是一名优秀的程序员,十分优秀!