多边形面积

如果给出不规则凸多边形所有顶点坐标,是否能求出其面积? - 知乎

 



points[0] = (x, y)
points[1] = (x, y)
points[2] = (x, y)
points[3] = (x, y)
polygon_area(points)

def polygon_area(corners):
   P=corners.tolist()
   n = len(P)
   P.append(P[0])
   S = 0
   for i in range(0, n):
      S = S + (P[i][0] + P[i + 1][0]) * (P[i + 1][1] - P[i][1])
   return 0.5 * abs(S)

你可能感兴趣的:(python基础,python)