Python弧方向

2024-09-28 05:18:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我在fme中使用python调用程序从带有aixm 4.5数据的点创建多边形

有些多边形包含圆弧,它们的顺时针方向(CWA)或逆时针方向(CCA)很重要,我不知道如何处理这个问题

以下是我目前掌握的代码:

import fme
import fmeobjects
from math import hypot
def replaceWithArc(feature):
    coords = feature.getAllCoordinates()
    x0, y0 = coords[0][0], coords[0][1] # coordinates of start of arc
    xc, yc = coords[1][0], coords[1][1] # coordinates of cetner of arc
    x2, y2 = coords[2][0], coords[2][1] # coordinates of end of arc

    vx0, vy0 = (x0 - xc), (y0 - yc) # vector: center -> start
    vx2, vy2 = (x2 - xc), (y2 - yc) # vector: center -> end
    vx1, vy1 = (vx0 + vx2), (vy0 + vy2) # vector: center -> middle
    len = hypot(vx1, vy1) # length of the vector
    radius = (hypot(vx0, vy0) + hypot(vx2, vy2)) * 0.5
    x1, y1 = xc + vx1 / len * radius, yc + vy1 / len * radius # coordinates of middle point on arc

threePoints = (
    fmeobjects.FMEPoint(x0, y0),
    fmeobjects.FMEPoint(x1, y1),
    fmeobjects.FMEPoint(x2, y2)
)
feature.setGeometry(fmeobjects.FMEArc(threePoints))

enter image description here


Tags: ofimportcoordsfeaturex2vectorxccoordinates
1条回答
网友
1楼 · 发布于 2024-09-28 05:18:01

在我看来,这三点似乎有问题。 你能粘贴这些值吗

从上面的图片来看,它看起来有点不对称,但我可能错了

您可以尝试的另一件事是使用不同的函数来初始化FMEArc,例如

  • init(twoPoints, bulge)
  • init(centerPoint, rotation, primaryRadius, secondaryRadius, startAngle, sweepAngle, startPoint, endPoint)

相关问题 更多 >

    热门问题