如何创建点对象列表?

时间:2013-08-25 16:22:43

标签: python point

我想在我的程序中使用以下功能:

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列表数据结构不同吗?我该如何创建这样的对象? 编辑:我应该提到列表将包含大约百万个随机点。

2 个答案:

答案 0 :(得分:2)

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

如果不是:

 from collections import namedtuple
 Point = namedtuple('Point', ['x','y'])

答案 1 :(得分: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