我需要在 2D 中定义一类多边形。由元组(坐标)列表定义的每个多边形,例如:
poly = [(0.5,0),(1,0.5),(0.5,1),(0,0.5)]
(不需要排序) 点从最左边的点开始顺时针排序。
我的任务是正确定义这个类
__init__
,__repr__
并且 is_inside(self, q)
检查天气点的函数在多边形内。
该__repr__
方法假设打印'[(0.5,0),(1,0.5),(0.5,1),(0,0.5)]'
到目前为止,这就是我所拥有的:
class Polygon2D:
def __init__(self, pts):
for index in range(len(pts)):
self.index = pts[index]
def __repr__(self):
return str(self)
当我尝试运行它时,程序崩溃了。请帮我!!