0

我想在我的程序中使用以下函数:

def computeVoronoiDiagram(points):
    """ Takes a list of point objects (which must have x and y fields).
Returns a 3-tuple of:

(1) a list of 2-tuples, which are the x,y coordinates of the
Voronoi diagram vertices
(2) a list of 3-tuples (a,b,c) which are the equations of the
lines in the Voronoi diagram: a*x + b*y = c
(3) a list of 3-tuples, (l, v1, v2) representing edges of the
Voronoi diagram. l is the index of the line, v1 and v2 are
the indices of the vetices at the end of the edge. If
v1 or v2 is -1, the line extends to infinity.
"""
    siteList = SiteList(points)
    context = Context()
    voronoi(siteList,context)
    return (context.vertices,context.lines,context.edges)

它说获取点对象列表(具有 x 和 y 字段)。它与 Python 列表数据结构不同吗?如何创建这样的对象?编辑:我应该提到列表将包含大约百万个随机点。

4

2 回答 2

2

您使用的库是否包含 Point 类?

如果不:

 from collections import namedtuple
 Point = namedtuple('Point', ['x','y'])
于 2013-08-25T16:40:56.430 回答
1

像这样的东西:

#!/usr/bin/python

class Point:
    def __init__(self, x, y):
        self.x = x;
        self.y = y;

def main():
    pointslist = [Point(0, 0)] * 10
    mytuple = computeVoronoiDiagram(pointslist)

if __name__ == "__main__":
    main()

显然,您需要其余代码computeVoronoiDiagram()和支持代码,并且听起来您希望随机化每个点的xy坐标,而不是将它们全部设置为0.

于 2013-08-25T16:28:42.260 回答