我只需要用坐标来计算多边形的周长。你知道吗
我的职能:
def definePerimeter(xCoords, yCoords):
i = 0
sum = 0
while xCoords[i] != xCoords[i+1] and yCoords[i] != yCoords[i+1]:
dx = xCoords[i] - xCoords[i+1]
dy = yCoords[i] - yCoords[i+1]
dsquared = dx**2 + dy**2
result = math.sqrt(dsquared)
print "The list of segments:"
print "The segment: ", result
i += 1
sum = sum + result
print "Total 2D Perimeter is " , sum ,"m" *
给出了错误的周长(与ArcGIS相比)。你知道吗
在python的多边形中,当第一个点最后一次相遇时,如何找到停止循环的方法?你知道吗
看到你的while循环条件,我猜你的最后和第一个坐标是一样的。你知道吗
我看不出while循环条件有任何其他意义。如果是这样,那你应该试试。你知道吗
这里不需要
while
循环。您可以使用for
循环来完成,因为您要遍历多边形的所有顶点:如果您坚持使用
while
循环执行此操作,您可以这样做:你的算法不正确。首先需要根据坐标与多边形质心所形成角度的反正切对坐标进行排序。(以获得形状中坐标的正确顺序)
然后,可以使用对坐标计算形状边的长度,并将所有边相加以获得周长:
相关问题 更多 >
编程相关推荐